LSpiker
asked on
How do I copy a text file from ftp to C:\ with .bat or .vbs?
I have tried a million different variations and cant seem to copy a text file from ftp to my desktop.
below is what I've tried:
Set objFS=CreateObject("Script ing.FileSy stemObject ")
strFile = ("ftp://tsc:xxxxxxxxx+@ftp.xyz.com/out/TABLES.txt")
strDestination = ("C:\Documents and Settings\xyz\Desktop\")
Set objFile =objFS.OpenTextFile(strFil e)
objfs.CopyFile objFile,strDestination
and always get an error for a bad file name or number
I've tried many of the other suggestions but get the same results.
below is what I've tried:
Set objFS=CreateObject("Script
strFile = ("ftp://tsc:xxxxxxxxx+@ftp.xyz.com/out/TABLES.txt")
strDestination = ("C:\Documents and Settings\xyz\Desktop\")
Set objFile =objFS.OpenTextFile(strFil
objfs.CopyFile objFile,strDestination
and always get an error for a bad file name or number
I've tried many of the other suggestions but get the same results.
A good related question here as well if you need to do it without using a utility.
https://www.experts-exchange.com/questions/27410499/batch-file-to-upload-to-ftp.html
~bp
https://www.experts-exchange.com/questions/27410499/batch-file-to-upload-to-ftp.html
~bp
ASKER
Can you give me mor info on the .BAT file builtin?
Save this as your batchfile after installing (copying) wget to a directory in your path:
cd %USERPROFILE%\Desktop
wget ftp://<username>:<password>@ftp.xyz.com/out/TABLES.txt
Ok some more examples here for the batch methods if you wish:
http://scripts.dragon-it.co.uk/links/batch-ftp-scripting
I favour the third approach on there generally:
If you want we can hide the password from being in the file using a method to hide it in an alternative data stream which is quite difficult for anyone to stumble across at least:
e.g. http://scripts.dragon-it.co.uk/links/batch-prompt-password-save-it
If you wanted to incoporate that into an ftp script it would be something like this below (without the fancier password box for first use):
http://scripts.dragon-it.co.uk/links/batch-ftp-scripting
I favour the third approach on there generally:
@echo off
(echo open ftp.xyz.com
echo user username
echo password
echo lcd "C:\Documents and Settings\xyz\Desktop"
echo cd /out
echo bin
echo get TABLES.TXT
echo quit
) | ftp -n -i
If you want we can hide the password from being in the file using a method to hide it in an alternative data stream which is quite difficult for anyone to stumble across at least:
e.g. http://scripts.dragon-it.co.uk/links/batch-prompt-password-save-it
If you wanted to incoporate that into an ftp script it would be something like this below (without the fancier password box for first use):
@echo off
set /p password=<%~nx0:password
if not "%password%"=="" goto OK
set /p Pwd=Enter password to save:
echo %pwd%>%~nx0:password
set password=%pwd%
:OK
@echo off
(echo open ftp.xyz.com
echo user username
echo %password%
echo lcd "C:\Documents and Settings\xyz\Desktop"
echo cd /out
echo bin
echo get TABLES.TXT
echo quit
) | ftp -n -i
exit /b
ASKER
http://scripts.dragon-it.co.uk/links/batch-ftp-scripting
I used this and got everything working except when it put the Tables.txt file on my desktop it was empty. Very Very close though.
My connection seems to work as I can open the ftp Tables.txt file with vbs but I can't copy
ASKER
Also I can physically copy the file from ftp and paste it on my desktop and it has data as well. Hmmmm.
OK. Good start then. Try it manually then for starters, i.e.
cmd.exe
ftp ftp.xyz.com
(enter username and password)
cd /out
bin
get tables.txt
dir
quit
notepad tables.txt
Does the dir command show it is an empty file, or has size?
Try it the same again then with the word "ASC" instead of "BIN". Could be it needs treating as an ASCII file rather than transferring exactly as is?
cmd.exe
ftp ftp.xyz.com
(enter username and password)
cd /out
bin
get tables.txt
dir
quit
notepad tables.txt
Does the dir command show it is an empty file, or has size?
Try it the same again then with the word "ASC" instead of "BIN". Could be it needs treating as an ASCII file rather than transferring exactly as is?
Could be your internet / remote connection won't support getting the file with ftp.exe if this is heading out through a firewall - it doesn't do "Passive mode" that is needed for some situations, though if this in a LAN environment it shouldn't be an issue.
Steve
Steve
ASKER
Oh here is the text file I used
open ftp.xxxxx.com
username abc
password xxxxxxx
lcd C:\Documents and Settings\xx\Desktop
cd /Out
bin
get Tables.txt
quit
and the call from the ftp.cmd file
@echo off
ftp -i -s:ftpscript.txt
open ftp.xxxxx.com
username abc
password xxxxxxx
lcd C:\Documents and Settings\xx\Desktop
cd /Out
bin
get Tables.txt
quit
and the call from the ftp.cmd file
@echo off
ftp -i -s:ftpscript.txt
OK... don't call it ftp.cmd btw, all sorts of problems with looping back around into itself!
what happens if you just type the commands manually like I said above, including the dir command to see what it brings back, and then see any results it shows when you do the get etc.
Steve
what happens if you just type the commands manually like I said above, including the dir command to see what it brings back, and then see any results it shows when you do the get etc.
Steve
ASKER
Here is what I used to open the file
Set objShell = CreateObject("WScript.Shel l")
objShell.run "ftp://xyz:sdddfdfdf+@ftp.xxx.com/out/Tables.txt"
and it opens the file in an explorer view.
Set objShell = CreateObject("WScript.Shel
objShell.run "ftp://xyz:sdddfdfdf+@ftp.xxx.com/out/Tables.txt"
and it opens the file in an explorer view.
ASKER
OK I tried it individually. I'm thinking its not hitting the ftp and just dropping a blank file on my desktop.
Now using the objshell. Like I showed you above I can open tha file very easily. Not sure how to copy from there though. I have tried the copyfile methods and move methods etc.etc.
Now using the objshell. Like I showed you above I can open tha file very easily. Not sure how to copy from there though. I have tried the copyfile methods and move methods etc.etc.
Ok, so that is using Internet explorer to handle the URL and open it. So going back to the ftp.exe script does the manual version work. If not we can probably give up on ftp.exe for your system. Have you tried wget as ws suggested above. Works good too and could be combined with hiding the password if needed again.
Steve
Steve
ASKER
Well it doesn't open in the ftp.exe. I would like to try the wget version however I am a contractor here and IT will not allow any downloads??? clients!!
ASKER
You know if I right click on the file in ftp it gives an option to export it to an excel file. I wonder if I could do that programatically since I can open it and see it?
Ok, moving back then.
Is this on the LAN or externally through WAN or the internet?
What happens when you manually do the ftp.exe commands I asked... i.e. post the output if you can?
Steve
Is this on the LAN or externally through WAN or the internet?
What happens when you manually do the ftp.exe commands I asked... i.e. post the output if you can?
Steve
ASKER
on Lan running it manually I'll be right with you
ASKER
OK I'm in to ftp on c:\ prompt now what should I try
ASKER
You know I want to check with IT tomorrow and see if they have any locks on this stuff.
thanks
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Got me on the right path for corrections. Thank you
No problem, glad it helped a bit.
Steve
Steve
http://www.gnu.org/s/wget/
~bp