Macro to move a file from desktop to an FTP folder

nicolewh

Well-known Member
Joined
Aug 7, 2009
Messages
554
I have a file, Test.txt on my desktop. I also have an FTP website. I want a macro to move 'test.txt' from my desktop to my website, ftp://mywebsite.com. I have been using this macro but it doesn't seem to work.
Code:
Sub Copy_One_File()
    FileCopy "C:\Users\Nicole\Desktop\Test.txt", "ftp:\\mywebsite.com\Test.txt"
End Sub
</pre>
Note: -I am able to save a file as ftp:\\mywebsite.com\Test.txt but not move it.
-My goal is to place a file in my ftp website as text tab delimited but I can't.
Thanks!

Nicole
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi Nicole,
I've not tried this myself with vba but one way is to use a vba Shell command to execute a command just as you would from a dos window. Some code has been published here (follow the link in post #2):
http://www.mrexcel.com/forum/showthread.php?t=484879
But I've seen simpler examples (maybe I can find one later tonight).

For what its worth, you can use windows explorer as an FTP tool - just fire it up and, instead of My Documents or Desktop, type your ftp address into windows explorer: ftp://mysite.com You'll be prompted for a user name and password and then you can drag and drop files to transfer them to/from your pc to the remote directory. Be aware that the FTP protocol does not encrypt passwords, which travel as plain text. Perhaps you need the script but you can't get much simpler than this.

ξ

Edit:
Okay, here was another link:
http://www.mrexcel.com/forum/showthread.php?t=8084
In this case, Colo is using a batch file which is basically just a text file with a series of commands to be executed at the FTP prompt. I'm sure I've seen other sorts of examples though. Darned if I don't save these somewhere. Personally I use Filezilla, which I prefer since I can use it to transfer files securely (i.e., with encryption) - but I've never automated it.
 
Last edited:
Upvote 0
Okay,
I gave it a go myself using code similar to what Colo posted, with success. My steps were:

1) Created a text file to be uploaded called C:\Test\somefile.txt
2) Created a batch file call C:\Test\testftp.bat
3) ran a shell command from VBA

the batch file listed the ftp commands, and in short was just a simple text file like this:
open mysite.com
username
password
send C:\Test\somefile.txt
bye


the vba shell command to execute the batch file (and, BTW, launch the ftp program) was simply:
Code:
Sub foo()
Call Shell("FTP -i -s:C:\Test\testftp.bat")
End Sub

You may want to open up a dos prompt and type ftp to get to an ftp prompt - you should be able to execute the very same commands from your .bat file, verbatim. But you'll get some messages if anything goes wrong. Note that this is a good reminder that the vba will execute without any warnings or errors even if it fails - so it can be a little trying at first and also may not guarantee success. It will also execute asynchronously so your VBA will not "wait" for the transfer to finish, but will continue on executing your vba even if the FTP program is not finished with the transfer. We've got a very simple implementation here.

As a footnote, (it probably doesn't apply to you as you're probably already using FTP outside of VBA) -- some computers, firewalls, or group policies will block ftp traffic.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top