Public Functionfunc_ftp (operation,servername,username,password,remotelocation,locallocation)'Set up the environmentConstInternet_open_type_direct =1Extern.declare Miclong,"InternetOpen","Wininet.dll","Internetopena", Micstring, Micdword, micstring, micstring, MicdwordDimhinternethinternet= Extern.internetopen ("qtp_ftp", Internet_open_type_direct, vbNullChar, vbNullChar,0 )IfHinternet =0 Thenfunc_ftp=Falsereporter.reportevent Micfail,"InternetOpen","Failed to setup environment."Exit FunctionEnd If'Open FTP ServerExtern.declare Miclong,"InternetConnect","Wininet.dll","internetconnecta", Miclong, micstring, Micinteger, micstring, micstring, Micdword, Micdword , MicdwordConstInternet_default_ftp_port = AConstInternet_service_ftp =1DimHconnecthconnect= Extern.internetconnect (Hinternet,servername,internet_default_ftp_port,username,password,internet_service_ftp,0,0 )IfHconnect =0 Thenfunc_ftp=Falsereporter.reportevent Micfail,"InternetConnect","Failed to open Internet connection."Exit FunctionEnd IfDimBretvalSelect Case LCase(Operation) Case "GetFile"'Get FileExtern.declare Micinteger,"FtpGetFile","Wininet.dll","Ftpgetfilea", Miclong, micstring, micstring, Micinteger, Micdword, Micdword, MicdwordConstFtp_transfer_type_ascii =1Bretval= Extern.ftpgetfile (Hconnect, remotelocation, Locallocation,False,0, Ftp_transfer_type_ascii,0) Wait (2)If not CBool(Bretval) Thenfunc_ftp=Falsereporter.reportevent Micfail,"FtpGetFile"& Remotelocation,"Failed to download file."&locallocationExit FunctionEnd If Case "Putfile" 'put fileExtern.declare Micinteger,"FtpPutFile","Wininet.dll","Ftpputfilea", Miclong, micstring, micstring, Micdwordbretval= Extern.ftpputfile (Hconnect,locallocation,remotelocation,0) Wait (2)If not CBool(Bretval) Thenreporter.reportevent Micfail,"FtpPutFile"& Locallocation,"Failed to upload file."&remotelocationfunc_ftp=FalseExit FunctionEnd If Case "DeleteFile"'Delete FileExtern.declare Micinteger,"Ftpdeletefile","Wininet.dll","Ftpdeletefilea", Miclong,micstringbretval=Extern.ftpdeletefile (hconnect,remotelocation) Wait (2)If not CBool(Bretval) Thenreporter.reportevent Micfail,"FtpPutFile","Failed to delete file.--"&remotelocationfunc_ftp=FalseExit FunctionEnd If Case "FindFile"DimWin32_find_dataextern.declare Micinteger,"Ftpfindfirstfile","Wininet.dll","Ftpfindfirstfilea", Miclong, Micstring,miclong, Micdwordbretval=extern.ftpfindfirstfile (hconnect,remotelocation,win32_find_data,internet_flag_no_cache_write) BRetval= Left(Bretval,2)IfBretval=0 Thenfunc_ftp=Falsereporter.reportevent Micfail,"File not Found","File not found."Exit FunctionEnd If Case Else End Select'Close ConnectionsExtern.declare Micinteger,"InternetCloseHandle","Wininet.dll","InternetCloseHandle", Miclongextern.internetclosehandle (hconnect) extern.internetclosehandle (hinternet)End Function
But Wininet.dll does ' t support SFTP
Ftp-download, Upload, Delete & Find Files