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

Just starting out? Need help? Post your questions and find answers here.
User avatar
silvercover
User
User
Posts: 86
Joined: Sat Aug 04, 2007 6:57 pm

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

Post 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.
infratec
Always Here
Always Here
Posts: 7583
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post 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
User avatar
silvercover
User
User
Posts: 86
Joined: Sat Aug 04, 2007 6:57 pm

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

Post by silvercover »

Thank you infratec, but it doesn't help. I use this method of getting progress from PB manual.
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

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

Post 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 ?
"Have you tried turning it off and on again ?"
A little PureBasic review
infratec
Always Here
Always Here
Posts: 7583
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post 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
User avatar
silvercover
User
User
Posts: 86
Joined: Sat Aug 04, 2007 6:57 pm

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

Post 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?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

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

Post 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:\
Last edited by ts-soft on Wed Aug 01, 2012 12:39 pm, edited 1 time in total.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

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

Post 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:
"Have you tried turning it off and on again ?"
A little PureBasic review
infratec
Always Here
Always Here
Posts: 7583
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

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

Post 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
Post Reply