Page 1 of 1

What's wrong with my code for downloading file via FTP?

Posted: Tue Jul 31, 2012 5:36 pm
by silvercover
Hi,

I try to get a file with this simple block of code, but nothing will be received. I've also attached debug window screenshot. what's wrong?

Code: Select all

  
InitNetwork()
  
  If OpenFTP(0, "ftp.xxxxx.net", "username", "password")
    Debug GetFTPDirectory(0)
    SetFTPDirectory(0, "first")
    Debug GetFTPDirectory(0)
    
    Result = ReceiveFTPFile(0, "file.txt", "c:\file.txt", #True)
 Repeat
    Debug FTPProgress(0)
    Delay(300)
  Until FTPProgress(0) = -3 Or FTPProgress(0) = -2

  Else
    Debug "Can't connect"
  EndIf
Image

Here is my ftp file and folder structure:

/
/first [Folder]
--- send_this_now.sql [File]
--- file.txt [File]

I have linux based server and all permissions are set to 755 or 777.

Re: What's wrong with my code for downloading file via FTP?

Posted: Tue Jul 31, 2012 5:53 pm
by infratec
Hi,

I tested it with:

Code: Select all

Repeat
  State = FTPProgress(0)
  Debug State
  Delay(10)
Until State = #PB_FTP_Finished Or State = #PB_FTP_Error
CloseFTP(0)
It works like expected.
The debug output is:

dir
dir
-1
-1
6048
:
:
20546
71844
-3

If you call FTPProgress() more than once, than you did not receive always the same result.
So I use it only one time in the loop.

Bernd

Re: What's wrong with my code for downloading file via FTP?

Posted: Tue Jul 31, 2012 9:21 pm
by silvercover
Thank you infratec, but it doesn't help. I use this method of getting progress from PB manual.

Re: What's wrong with my code for downloading file via FTP?

Posted: Tue Jul 31, 2012 10:33 pm
by luis
What about "Result" ?

It would be better for us to be able to try it with your server. Half of the equation is the code above, the other is on the server.

Did you try it with asynchronous off ?

Re: What's wrong with my code for downloading file via FTP?

Posted: Wed Aug 01, 2012 7:16 am
by infratec
Hi,

have you tried it already 'manual':

Run 'cmd' and than use 'ftp' to do it by hand.
If this works, than the PB code works also.

Bernd

Re: What's wrong with my code for downloading file via FTP?

Posted: Wed Aug 01, 2012 12:30 pm
by silvercover
infratec wrote:Hi,

have you tried it already 'manual':

Run 'cmd' and than use 'ftp' to do it by hand.
If this works, than the PB code works also.

Bernd

The strange thing is that when I set local path to drive C: (c:\file.txt) nothing happens, but when I choose different
location such as d:\file.txt it works fine!

I've tested with both Windows FTP and PB and they act similar to what I said. Is that something wrong with C:
or am I missing something here?

Re: What's wrong with my code for downloading file via FTP?

Posted: Wed Aug 01, 2012 12:37 pm
by ts-soft
You require on newer OS Admin-Privilege to write on C:\ !

It is never a good idea to write on the root of C:\

Re: What's wrong with my code for downloading file via FTP?

Posted: Wed Aug 01, 2012 12:38 pm
by luis
Sound like a permissions problem. Are you a standard user ? Try to save in your user's home.

EDIT: thomas was faster :wink:

Re: What's wrong with my code for downloading file via FTP?

Posted: Wed Aug 01, 2012 1:21 pm
by infratec
Hi,

you are a victim of UAC (UserAccessControl)
Since Vista you are not allowed to do several things.
One of them is to write in the root directory of your system volume. :mrgreen:

Bernd