Solved

FTP Put to Subfolder

Posted on 2014-01-19
7
890 Views
Last Modified: 2014-01-20
I am trying to use VBA code to upload a file to a SUBFOLDER on a FTP Server. I am successful when I upload directly to the ROOT of the FTP site. When I try to upload to the Subfolder, I get the message "unknown host."

My code looks like this:

    strFTPServ = "ftp://destination.com/uploads"
    strGet = "c:\SourceFolder\" & strFile
    'Mounting file command for ftp.exe
    lngNum = FreeFile()
    Open PATHLOCAL & "\FtpComm.txt" For Output As #lngNum
    Print #1, "user myuser mypassword" 
    Print #1, "bin" 
    Print #1, "put " & strGet ' Send File
    Print #1, "close" ' close connection
    Print #1, "quit" ' Quit ftp program
    Close
    strShell = "ftp -i -n -s:" & PATHLOCAL & "FtpComm.txt " & strFTPServ
    Shell strShell

Open in new window

   

If I remove the /Uploads, the code works PERFECTLY. I am certain that the folder on the FTP server is called Uploads.
0
Comment
Question by:TechMommy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 3

Expert Comment

by:Conner Turner
ID: 39793175
Hello There,

The FTPserver is not reserved for the destination of the FTP FQDN or IP and serves no purpose to where your file goes, you will need to either name your file with the / Directory and FTP will place it under the named Directory or modify your Script to contain a Directory by Duplicating the Send file or Printing the cd command to another Dir.

HTH,
Conner
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 39793177
The location where you want to put the file should be specified in your text file.

Change lines 1 and 2 to the following:
strFTPServ = "ftp://destination.com"
strGet = "c:\SourceFolder\" & strFile & " /uploads/" & strFile 

Open in new window

0
 
LVL 11

Author Comment

by:TechMommy
ID: 39793216
This makes perfect sense, but when I modify the strFTPServ and strGet as suggested by IrogSinta, I no longer receive the error, but the file appears to be placed in the root folder.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 150 total points
ID: 39793288
Basic FTP connections are to the 'root' folder of your account.  To get to any other folder, you must change the current directory with 'cd'.  Many FTP clients will do this for you but if you're writing the code, you have to do it for youself.

http://en.wikipedia.org/wiki/List_of_FTP_commands

Some more examples:  http://www.cs.colostate.edu/helpdocs/ftp.html
0
 
LVL 29

Accepted Solution

by:
IrogSinta earned 350 total points
ID: 39793332
Looks like Dave is right about the root folder so revise your code to this:
    strFTPServ = "ftp://destination.com"
    strGet = "c:\SourceFolder\" & strFile
    'Mounting file command for ftp.exe
    lngNum = FreeFile()
    Open PATHLOCAL & "\FtpComm.txt" For Output As #lngNum
    Print #1, "user myuser mypassword" 
    Print #1, "bin" 
    Print #1, "cd uploads" 
    Print #1, "put " & strGet ' Send File
    Print #1, "close" ' close connection
    Print #1, "quit" ' Quit ftp program
    Close
    strShell = "ftp -i -n -s:" & PATHLOCAL & "FtpComm.txt " & strFTPServ
    Shell strShell

Open in new window

0
 
LVL 11

Author Closing Comment

by:TechMommy
ID: 39793403
Thank you both for helping me to solve this. It works perfectly now!
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39793647
You're welcome, glad to help.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question