Ftp-download, Upload, Delete & Find Files

Source: Internet
Author: User

 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.