Solved

FTP Put to Subfolder

Posted on 2014-01-19
7
934 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

617 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