Jump to content
Mattw11486

How to check if a file exists on FTP side?

Recommended Posts

I want the code to check to see if the file already exists on the ftp side before it copies the file over in the server to prevent overwrites. If the file does exist it loops back to step 1 on constantly checking until the file on the FTP is no longer there/deleted, then it will send the file to the FTP. I am not sure how to execute this.

 

While 1
    sleep(300)
If FileExists("C:\cygwin32\home\Sapphire\cwe\lib\etc\bonus_activation.txt") Then
   $Open = _FTP_Open('MyFTP Control')
   $Conn = _FTP_Connect($Open, $server, $username, $pass)
   $Ftpp = _FTP_FilePut($Conn, 'C:\cygwin32\home\Sapphire\cwe\lib\etc\bonus_activation.txt', '/bonus_activation.txt')
   $Ftpc = _FTP_Close($Open)
   FileDelete("C:\cygwin32\home\Sapphire\cwe\lib\etc\bonus_activation.txt")
EndIf
Wend

 

Share this post


Link to post
Share on other sites
Posted (edited)
Quote

How to check if a file exists on the FTP side?

I find it hard to believe that you looked thru all of the _FTP* functions in the help file and didn't see any that may be able to tell you if a particular file exists on the FTP server, but assuming that's the case, here are a couple of ways you do it:

  1. You could use _FTP_FileGetSize and if it returns an error, then the file most likely does not exist.  Of course this assumes that you supplied the appropriate file name.
  2. You could use _FTP_ListToArray after making sure that you are looking in the right directory using _FTP_DirSetCurrent.  Then you could search the resulting array to see if the desired file exists.

Of course both of the ways above assume that you are able to successfully connect and communicate with the FTP server.

Edited by TheXman

Share this post


Link to post
Share on other sites
Posted (edited)

I did look through the ftp functions and did not find anything that matched up to what I was looking for, then again I am new at this which is the purpose of the post, but thanks for your helpful comment.

Edited by Mattw11486

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...