Solved

FTP Put to Subfolder

Posted on 2014-01-19
7
852 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
  • 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

820 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