Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Downloading Files from FTP

Status
Not open for further replies.

vj

Programmer
Nov 18, 2000
58
0
0
MU
hi guys,

iam using the MS Internet Transfer Control 6.0(SP4) and these are the lines i'v written to download a specified file. can anyone tell me how to specify the destination path along with destination file name and if the below lines are ok !

WITH THISFORM
.Ftp.UserName=ALLTRIM(THISFORM.TxtUsername.Value)
.Ftp.Password=ALLTRIM(THISFORM.TxtPassword.Value)
.Ftp.URL="FTP://" + .Ftp.UserName + ":" + .Ftp.Password + '@' + ALLTRIM(THISFORM.TxtFTPAddress.Value)
.Ftp.Execute(.Ftp.URL , 'GET ' + ALLTRIM(.TxtRemoteFile.Value))
ENDWITH

thankx alot
 
I'm not sure, but i THINK your Execute() line needs to include the local file name
and the second parameter, the original URL not being required:

I got this from here:
I think it is VB rather than VFP - but it should point you in the right direction.

Code:
With Inet1
   .URL = "ftp://ftp.someFTPSite1020.com"
   .UserName = "John Smith"
   .Password = "mAuI&9$6"
   .Execute ,"DIR"   ' Returns the directory.
   .Execute ,"CLOSE" ' Close the connection.
End With


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
Vijay,

You're close, but not quite right. The control has only one method that is relevent here, and that is the Execute method. This takese two parameters: the URL of the FTP site, and the command to be executed. So, assuming iNet1 is the name you have given the control, you need this:

Code:
lcURL = .... && put the URL here
lcFile ..... && name of file on remote server
lcLocal .... && path and name to save the file to
THISFORM.iNet1.Execute(lcURL, "GET " + lcFile + " " + lcLocal)

You might need to pause your program for a few moments while the file is downloading. To do so:

Code:
DO WHILE THISFORM.iNet1.StillExectuing
ENDDO

There is an alternative approach. You can use the control's OpenURL() method instead. This returns the contents of the file as a string, which you can then save to disk or do anything else you like with:

Code:
lcFileURL = .... && URL of the remote file
lcLocal .... && path and name to save the file to
lcMyFile = THISFORM.iNet1.OpenURL(lcFileURL)
STRTOFILE(lcMyFile, lcLocal)

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
hi guys,

i'v tried this (but no results ... )

FTPURL="ftp://"+THISFORM.TxtUsername.Value+":"+THISFORM.TxtPassword.Value+'@'+THISFORM.TxtFTPAddress.Value
SOURCEFILE=ALLTRIM(THISFORM.TxtRemoteFile.Value)
DESTINATIONFILE=ALLTRIM(THISFORM.TxtLocalFile.Value)
THISFORM.Ftp.Execute(FTPURL , "'GET " + SOURCEFILE + " " + DESTINATIONFILE+"'")

then
i tried this (...if I put only file name without extension for sourcefile .. I get a file but it is just 0 kb .. and is damaged,, does not openup ) and when I specify sourcefile with extension .zip I get error "OLE Idispatch exception code ) from Inet : request timed out"

FLURL="ftp://test:test@46.24.20.103/RESTO1/Hourly1406090200"
TO_FILE=ALLTRIM(THISFORM.TxtLocalFile.Value)
FTPEXECUTE=THISFORM.FTP.OpenURL(FLURL)
STRTOFILE(FTPEXECUTE,TO_FILE)

am I missing something here.

thankx
vijay
 
FTPURL="ftp://"+THISFORM.TxtUsername.Value+":"+THISFORM.TxtPassword.Value+'@'+THISFORM.TxtFTPAddress.Value

I suggest you execute [tt]? FTPURL[/tt] after the above line, to check that it contains what you expect.

You might need to ALLTRIM() the three values (user name, password and FTP address). Also, are these values case-sensitive?

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 


ya mike ... i'v put all three inside the alltrim() ... I just didn't show it on my previous post ...anyway .... it is still the same ,,,, with alltrim() also ... I see the mouse pointer being busy ... like something is happening .. but I don't get any file. by-the-way ... I even put it as the values originally are .. in the 2nd approach ... FLURL="ftp://test:test@46.24.20.103/RESTO1/Hourly14060902" this gives me a file which is just 0kb in size. by-the-way ... these files on ftp://46.24.20.103/RESTO1/ are all .zip files ... and iam also specifying the correct username and password for the ftp which is test , test . maybe iam missing something in the syntax ... ?

thankx
 
>when I specify sourcefile with extension .zip I get error "OLE Idispatch exception code ) from Inet : request timed out"
Well, then the problem simply is a too large ZIP file, you can't download it fully within a time out. Removing the file extension is not a solution.

How to higher the time out? I don't know, sorry. But your code is not the problem.

Bye, Olaf.
 
hi olaf,

you'll be surprised to know the .zip files are very small in size .. less than 15 kb ... that is what i thought when i got the request timed out msg .. i thought the file was not copied in that much time .... but the file is very small just 10kb or 15kb max.
is there any other way to do this ftp thing .

thankx alot
 
Before you try an alternative, did you manually try FTPing with any FTP client or DOS/Comandshell FTP command?

Bye, Olaf.

 
i just made a ping to the ftp server address from the command prompt ... ping 46.24.20.103 and iam getting back the response with 0% loss ... so my pc can see the ftp server .. that is fine.

thankx
vijay
 
hi guys ... is there something about the port .. that should be included ... like the port number ... just got an idea .. coz .. no-one mentioned the port .... in the syntax ?

thankx
Vijay
 
Vijay,

Here's something you can try:

Add this code to the StateChanged event of your Internet Transfer Control (you only need to add the third line; the other two should already be there):

Code:
*** ActiveX Control Event ***
LPARAMETERS state

WAIT WINDOW state NOWAIT

Now, as soon as you start the transfer, observe the wait window in the top-right of the screen. It should display a number, 1 - 12, which indicates the state of the transfer. See how high it goes. Then use the table here to see how far you get.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
The default value for the Remoteport is 80 (HTTP), and you are using a ftp://-URL, that you can also enter in a browser and that would do FTP over HTTP - Well, I'm not the protocol guy, but I think that's what happens in a browser.

If you really want to use the FTP protocol you have to use the FTP Port, yes, that's remote port 21. And the Username/Password properties instead of user/pass embedded in the URL. The URL would only be ftp.sample.com/dir/ and the file name is put into the Execute as Mike posted earlier.

Bye, Olaf.

 
Another thing to keep in mind is that sometimes the remote source is an SFTP (SSH) site instead of an FTP site. Sometimes they 'forget' to tell you that.

If so you would need to utilize a different port.

Your best bet is to communicate with the technical support individuals at the remote location and get their FULL specifications.

Good Luck,
JRB-Bldr
 
mike .. I did put the ---> WAIT WINDOW state NOWAIT .. line in the StateChanged event of the active x control and it's the same .. I don't even see the wait window which should show me the increasing values ? maybe something to do with the settings for the control ? I right click on the active X control and go to Inet properties and on the general tab - access type is set to 0-Icuse default , proxy set to blank , request time out set to 120 and in the URL Tab .. URL is set to blank , Protocol set to 2-IcFTP , remote host set to blank, remote port set to 21, document & username & password all set to blank . I think the blank values will be populated with values from my form Right ?

by-the-way ... can you check if your ftp form with the same MS Internet Transfer Control 6.0(SP4) is able to do the task iam trying to do ?

thankx guys
 
You might want to look at Dave Summer's FAQ titled:
How do I transfer files using FTP?
faq184-3234​

I have used his routines (customized where necessary due to specific remote-side requirements) and they have worked VERY well for me.

Good Luck,
JRB-Bldr


 
In some cases the properties dialog of an activex control sets proeprties you can't set via code, becuase they arent's public object properties, but in this case you can set the protocol, Url, port etc. via the properties in code.

If you have set FTP as potocol your URL mustn't be ftp://ftp.server.com/dir/filename, it must be ftp.server.com/dir and the file name you want to get is in he FTP GET command you will excecute after connecting. With HTTP you don't connect to a server, you get a resource, with FTP you connect to a dir, not to a single file, that's the big difference.

Bye, Olaf.
 
I'm not arguing with any suggestions made in this thread, but I found ISTOOL invaluable.
It is part of Inno setup, and even I could work it out............
 
I found ISTOOL invaluable

If I remember rightly, ISTOOL is the part of Inno that provides a user interface for automatically generating a setup script.

If that's right, what on earth has it got to do with Internet Transfer Control? Or anything else that would solve Vijay's problem?

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
hi everyone,

ok ... i'v managed to copy the file(s) from the ftp server ... i used the FTPGet.PRG from ---

Dave Summer's FAQ titled
FAQ184-3234: How do I transfer files using FTP?

thanks JRB-Bldr and thanks alot to everyone else too

... hmmm .. ... i just need to play a little more with the MS Internet Transfer Control 6.0(SP4) and iam sure even this should work . I will post my feedback .. once i get the control to work ... maybe it's something to do with the directory path ...

thankx alot
vijay
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top