Excel VBA et transfer FTP
Bonjour à tous,
Voila je fais encore appel à votre précieuse aide !
J'ai une procédure pour transférer un fichier sur le serveur Ftp. Le problème est que tout fonctionne quand je transfère un fichier .txt, mais si je veux transférer un fichhier .jpg ca ne marche plus !!
je ne comprends pas d'ou vient le problème. Si on peux me donner un coup de main !
Voila la procédure :
Declare PtrSafe 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
Declare PtrSafe 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
Declare PtrSafe Function FtpSetCurrentDirectory Lib "wininet.dll" Alias _
"FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, _
ByVal lpszDirectory As String) As Boolean
Declare PtrSafe Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" ( _
ByVal hConnect As Long, _
ByVal lpszLocalFile As String, _
ByVal lpszNewRemoteFile As String, _
ByVal dwFlags As Long, _
ByRef dwContext As Long) As Boolean
Sub FtpFileUpload()
Dim ftp, FTP_PORT, user, password, loc_file, remote_file, ftp_folder As Variant
x_dir = "web/chr/image/img_r"
'f_img = "image1.jpg"
f_img = "readme.txt"
ftp_folder = x_dir
loc_file = ThisWorkbook.Path & "\" & f_img
remote_file = ftp_folder & "/" & f_img
FTP_PORT = "21"
user = "Patrick"
password = "****"
ftp = "192.x.x.x"
Internet_OK = InternetOpen("", 1, "", "", 0)
If Internet_OK Then
FTP_OK = InternetConnect(Internet_OK, ftp, FTP_PORT, user, password, 1, 0, 0) ' INTERNET_DEFAULT_FTP_PORT or port no
If FtpSetCurrentDirectory(FTP_OK, "/") Then
Success = FtpPutFile(FTP_OK, loc_file, remote_file, FTP_TRANSFER_TYPE_BINARY, 0)
End If
End If
If Success Then
Debug.Print "ftp success ;)"
MsgBox "ftp success ;)"
Else
Debug.Print "ftp failure :("
MsgBox "ftp failure :("
End If
End SubMerci pour votre aide
Cordialement
Bonjour
Pour info j'ai résolu le problème. C'était le chemin local qui était pas correct !
loc_file = ThisWorkbook.Path & "\" & f_imgil fallait mettre
loc_file = ThisWorkbook.Path & "\Images\" & f_imgBonne journée
Cdlt
Bonjour,
Pour un travail de copie ou déplacement de fichier sur un FTP pourquoi ne pas avoir créer un raccourci réseau Windows.
Les adresses en seraient simplifiées dans les codes vba.
https://www.generation-nt.com/creer-un-raccourci-ftp-astuce-24619-1.html