Cos'è ElectroYou | Login Iscriviti

ElectroYou - la comunità dei professionisti del mondo elettrico

Creazione Cartella FTP tramite VBA

Linguaggi e sistemi

Moderatori: Foto UtentePaolino, Foto Utentefairyvilje

0
voti

[11] Re: Creazione Cartella FTP tramite VBA

Messaggioda Foto Utentealev » 18 nov 2021, 18:08

Nel post [5] c'è un link, fai qualche prova e posta gli eventuali errori che rilevi
Avatar utente
Foto Utentealev
5.990 2 9 12
free expert
 
Messaggi: 6283
Iscritto il: 19 lug 2010, 14:38
Località: Altrove

0
voti

[12] Re: Creazione Cartella FTP tramite VBA

Messaggioda Foto Utentelelerelele » 18 nov 2021, 18:36

Bobo360 ha scritto:ok, ma il comando pre creare la cartella?
mi accontento pure con il comando shell, ma anche qui, come creo la cartella?

#-o
Cosa c'è che non è chiaro? Hai dimestichezza con VBA? Hai apeto i link al post [7] e letti?
Avatar utente
Foto Utentelelerelele
4.899 3 7 9
Master
Master
 
Messaggi: 5505
Iscritto il: 8 giu 2011, 8:57
Località: Reggio Emilia

1
voti

[13] Re: Creazione Cartella FTP tramite VBA

Messaggioda Foto UtenteGioArca67 » 18 nov 2021, 19:06

Prova a leggere
qui
e
qui

potresti ad esempio fare qualcosa del genere:
Codice: Seleziona tutto
Option Explicit

Const MAX_PATH As Integer = 260
Const INTERNET_SERVICE_FTP = 1
Const INTERNET_FLAG_RELOAD = &H80000000
Const INTERNET_FLAG_NO_CACHE_WRITE = &H4000000

Private Type WIN32_FIND_DATA
    dwFileAttributes As Long
    ftCreationTime As Currency
    ftLastAccessTime As Currency
    ftLastWriteTime As Currency
    nFileSizeHigh As Long
    nFileSizeLow As Long
    dwReserved0 As Long
    dwReserved1 As Long
    cFileName As String * MAX_PATH
    cAlternate As String * 14
End Type


#If VBA7 Then
    Private Declare PtrSafe Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _
    (ByVal sAgent As String, _
    ByVal lAccessType As LongPtr, _
    ByVal sProxyName As String, _
    ByVal sProxyBypass As String, _
    ByVal lFlags As LongPtr) As LongPtr
     
    Private Declare PtrSafe Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" _
    (ByVal hInternetSession As LongPtr, _
    ByVal sServerName As String, _
    ByVal nServerPort As Integer, _
    ByVal sUsername As String, _
    ByVal sPassword As String, _
    ByVal lService As LongPtr, _
    ByVal lFlags As LongPtr, _
    ByVal lContext As LongPtr) As LongPtr
     
    Private Declare PtrSafe Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" _
    (ByVal hFtpSession As LongPtr, _
    ByVal lpszDirectory As String) As Boolean

    Private Declare PtrSafe Function FtpCreateDirectory Lib "wininet.dll" Alias "FtpCreateDirectoryA" _
    (ByVal hFtpSession As LongPtr, _
    ByVal lpszDirectory As String) As Boolean
     
    Private Declare PtrSafe Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" _
    (ByVal hFtpSession As LongPtr, _
    ByVal lpszSearchFile As String, _
    lpFindFileData As WIN32_FIND_DATA, _
    ByVal dwFlags As LongPtr, _
    ByVal dwContent As LongPtr) As LongPtr
     
    Private Declare PtrSafe Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" _
    (ByVal hFind As LongPtr, _
    lpFindFileData As WIN32_FIND_DATA) As LongPtr
     
    Private Declare PtrSafe Function InternetCloseHandle Lib "wininet.dll" _
    (ByVal hInet As LongPtr) As Integer
   
#Else
    Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _
    (ByVal sAgent As String, _
    ByVal lAccessType As Long, _
    ByVal sProxyName As String, _
    ByVal sProxyBypass As String, _
    ByVal lFlags As Long) As Long
     
    Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" _
    (ByVal hInternetSession As Long, _
    ByVal sServerName As String, _
    ByVal nServerPort As Integer, _
    ByVal sUsername As String, _
    ByVal sPassword As String, _
    ByVal lService As Long, _
    ByVal lFlags As Long, _
    ByVal lContext As Long) As Long
     
    Private Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" _
    (ByVal hFtpSession As Long, _
    ByVal lpszDirectory As String) As Boolean
     
    Private Declare Function FtpCreateDirectory Lib "wininet.dll" Alias "FtpCreateDirectoryA" _
    (ByVal hFtpSession As LongPtr, _
    ByVal lpszDirectory As String) As Boolean

    Private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" _
    (ByVal hFtpSession As Long, _
    ByVal lpszSearchFile As String, _
    lpFindFileData As WIN32_FIND_DATA, _
    ByVal dwFlags As Long, _
    ByVal dwContent As Long) As Long
     
    Private Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" _
    (ByVal hFind As Long, _
    lpFindFileData As WIN32_FIND_DATA) As Long
     
    Private Declare Function InternetCloseHandle Lib "wininet.dll" _
    (ByVal hInet As Long) As Integer
   
#End If

Public Sub TestFTP()
 
    #If VBA7 Then
        Dim hOpen As LongPtr, hConn As LongPtr, hFind As LongPtr, ret As LongPtr, ftpMode As LongPtr
    #Else
        Dim hOpen As Long, hConn As Long, hFind As Long, ret As Long, ftpMode As Long
    #End If
   
    Dim hostName As String, username As String, password As String
    Dim remoteDirectory As String, remoteMatchFiles As String, sTargetFileName As String
    Dim fileFind As WIN32_FIND_DATA
    Dim fDate As Date
    Dim port As Integer, iCount As Integer
   
    'testing the ftp functions
     '========== User-defined settings ==========
    hostName = "ccc.aaa.it"
    port = 21
    username = ""
    password = ""
    remoteDirectory = "/dddd/"
    remoteMatchFiles = "*"
     '===========================================
     
    ftpMode = 1 'active mode FTP
     
    ret = InternetOpen("ftp VBA", 1, vbNullString, vbNullString, 0)
    hOpen = ret
   
    If ret > 0 Then
        ret = InternetConnect(hOpen, hostName, port, username, password, INTERNET_SERVICE_FTP, ftpMode, 0)
        hConn = ret
    End If
     
    If ret > 0 Then
        ret = FtpSetCurrentDirectory(hConn, remoteDirectory)
    End If
     
    If ret > 0 Then
       
        'find first file
        fileFind.cFileName = String(MAX_PATH, 0)
        ret = FtpFindFirstFile(hConn, remoteMatchFiles, fileFind, INTERNET_FLAG_RELOAD Or INTERNET_FLAG_NO_CACHE_WRITE, 0)
       
        hFind = ret
       
        While ret > 0
           
            iCount = iCount + 1
            sTargetFileName = Left((fileFind.cFileName), InStr(1, fileFind.cFileName, String(1, 0), vbBinaryCompare) - 1)
           
            fDate = CDate((fileFind.ftLastWriteTime / 86400000#) - 109205#)

            'print the file name and date
            Debug.Print "Found " & sTargetFileName & vbTab & fDate
           
            'Find next matching file
            fileFind.cFileName = String(MAX_PATH, 0)
            ret = InternetFindNextFile(hFind, fileFind)
        Wend

    End If

    InternetCloseHandle hFind
    InternetCloseHandle hConn
    InternetCloseHandle hOpen
End Sub

(adattato da qui)

Nell'ultimo if metti il codice che ti serve con la FtpCreateDirectory

Volendo gli Shell puoi guardare qui
Avatar utente
Foto UtenteGioArca67
4.580 4 6 9
Master EY
Master EY
 
Messaggi: 4592
Iscritto il: 12 mar 2021, 9:36

0
voti

[14] Re: Creazione Cartella FTP tramite VBA

Messaggioda Foto Utentelelerelele » 19 nov 2021, 9:43


Foto UtenteGioArca67 Alla faccia del complicato per avere una cosa semplice. :shock:


Script VBA creato ed eseguito su ACCESS, (non so che programma usi l'OP, per farci su script VBA).

Codice: Seleziona tutto
Private Sub Corpo_Click()

Dim path As String

path = "\\TECNICO2\Desktop\rrr"

MkDir path

End Sub


Questa, eseguendo l'evento, Corpo_Click(), mi crea direttamene la cartella "rrr" sul PC a fianco.

saluti
Avatar utente
Foto Utentelelerelele
4.899 3 7 9
Master
Master
 
Messaggi: 5505
Iscritto il: 8 giu 2011, 8:57
Località: Reggio Emilia

0
voti

[15] Re: Creazione Cartella FTP tramite VBA

Messaggioda Foto UtenteBobo360 » 19 nov 2021, 10:17

Grazie a tutti per il supporto, io avevo provato questo codice:

Immagine

avrò dimenticato qualche dichiarazione. perché mi segnala delle stringhe in rosso.
mi sembrava un codice snello.

nel frattempo sto studiando i post che mi avete mandato.

grazie
Avatar utente
Foto UtenteBobo360
30 4
Frequentatore
Frequentatore
 
Messaggi: 153
Iscritto il: 12 nov 2008, 12:55

0
voti

[16] Re: Creazione Cartella FTP tramite VBA

Messaggioda Foto UtenteBobo360 » 19 nov 2021, 10:21

lelerelele ha scritto:
Foto UtenteGioArca67 Alla faccia del complicato per avere una cosa semplice. :shock:


Script VBA creato ed eseguito su ACCESS, (non so che programma usi l'OP, per farci su script VBA).

Codice: Seleziona tutto
Private Sub Corpo_Click()

Dim path As String

path = "\\TECNICO2\Desktop\rrr"

MkDir path

End Sub


Questa, eseguendo l'evento, Corpo_Click(), mi crea direttamene la cartella "rrr" sul PC a fianco.

saluti


ho un Database in access, ma questo codice crea la cartella in locale LAN. non in FTP.
Per leggere su FTP uso questo:

Codice: Seleziona tutto
DoCmd.OpenForm "basketftp"
Forms!basketftp!Testo2.Value = "ftp://user:pass@ip:port/Manutenzione/" '  & Me.Chiamata.Value & "/"


e apro la finestra con i file dentro.
Ma mi serve questo comando quando la cartella non c'è e devo crearla.
Avatar utente
Foto UtenteBobo360
30 4
Frequentatore
Frequentatore
 
Messaggi: 153
Iscritto il: 12 nov 2008, 12:55

0
voti

[17] Re: Creazione Cartella FTP tramite VBA

Messaggioda Foto Utentelelerelele » 19 nov 2021, 10:32

non l'ho mai fatto Foto UtenteBobo360, dai un occhio qua, in FTP

saluti
Avatar utente
Foto Utentelelerelele
4.899 3 7 9
Master
Master
 
Messaggi: 5505
Iscritto il: 8 giu 2011, 8:57
Località: Reggio Emilia

0
voti

[18] Re: Creazione Cartella FTP tramite VBA

Messaggioda Foto UtenteGioArca67 » 19 nov 2021, 11:18

lelerelele ha scritto:
Foto UtenteGioArca67 Alla faccia del complicato per avere una cosa semplice. :shock:


Yesss....
non proprio il modo più veloce, ma...
lelerelele ha scritto:Script VBA creato ed eseguito su ACCESS, (non so che programma usi l'OP, per farci su script VBA).

Codice: Seleziona tutto
Private Sub Corpo_Click()

Dim path As String

path = "\\TECNICO2\Desktop\rrr"

MkDir path

End Sub


Questa, eseguendo l'evento, Corpo_Click(), mi crea direttamene la cartella "rrr" sul PC a fianco.

saluti



... MkDir non funziona su FTP.
O_/
Avatar utente
Foto UtenteGioArca67
4.580 4 6 9
Master EY
Master EY
 
Messaggi: 4592
Iscritto il: 12 mar 2021, 9:36

0
voti

[19] Re: Creazione Cartella FTP tramite VBA

Messaggioda Foto Utentelelerelele » 19 nov 2021, 11:22

Si Foto UtenteGioArca67, non avendolo mai fatto non ne avevo idea, ora lo so. :ok:

Saluti.
Avatar utente
Foto Utentelelerelele
4.899 3 7 9
Master
Master
 
Messaggi: 5505
Iscritto il: 8 giu 2011, 8:57
Località: Reggio Emilia

0
voti

[20] Re: Creazione Cartella FTP tramite VBA

Messaggioda Foto Utentealev » 19 nov 2021, 11:29

Se il job avviene all'interno della sessione FTP, penso che il comando interno di FTP potrebbe funzionare, quindi deve essere minuscolo
Codice: Seleziona tutto
mkdir


oppure provare con un comando shell incapsulato nella sessione
Codice: Seleziona tutto
!mkdir
Avatar utente
Foto Utentealev
5.990 2 9 12
free expert
 
Messaggi: 6283
Iscritto il: 19 lug 2010, 14:38
Località: Altrove

PrecedenteProssimo

Torna a PC e informatica

Chi c’è in linea

Visitano il forum: Nessuno e 55 ospiti