Skip to main content
Inspiring
April 9, 2019
Answered

CFFTP upload from local machine

  • April 9, 2019
  • 5 replies
  • 3957 views

<cfset ftpurl=ftp.myserver.com>
<cfset ftpusername="myusername">
<cfset ftppassword="mypassowrd">
<cfset ftplocal="C:\Users\MyUser\Documents\MyFile.txt">
<cfset ftpremote="MyFile.txt">

<cfftp connection = "Myftp"
action = "PutFile"
localFile="#ftplocal#"
remoteFile="#ftpremote#"
failifexists="no"
passive = "Yes">

I use above code to copy a local file from local machine to FTP server.

I checked that the file exists and spelling is correct, but I got following error

(The system cannot find the path specified).           

Any suggestions is great appreciated,

Regards,

Souries

This topic has been closed for replies.
Correct answer BKBK

I use cfoutput to check the file name using CFFILE UPLOAD and see the file name change to localhost tmp folder,

Is it possible that the I need use CFFILE UPLOAD to the server and using FTP PutFile using the server temp file, if yes, are there any sample code to access this temp file for FTP PutFile.

Thanks again for helping,

\MyApp\runtime\work\Catalina\localhost\tmp\

Regards,


iccsi  wrote

I use cfoutput to check the file name using CFFILE UPLOAD and see the file name change to localhost tmp folder,

Is it possible that the I need use CFFILE UPLOAD to the server and using FTP PutFile using the server temp file, if yes, are there any sample code to access this temp file for FTP PutFile.

Thanks again for helping,

\MyApp\runtime\work\Catalina\localhost\tmp\

This question now makes me guess that you have 3 separate machines: your local Windows, the machine hosting ColdFusion and the FTP server. Is that so?

If so, then, yes, it might be a good idea to first upload the file from your local machine to the server hosting ColdFusion. What kind of machine is hosting ColdFusion: Linux or Windows?

5 replies

Charlie Arehart
Community Expert
Community Expert
April 12, 2019

iccsi, you changed horses on us mid-stream, when you added the wrinkle of using cffile upload processing.

When you first wrote, the file you named was already on the server. And going back to that, I suspect I see now what was wrong with that  (on rereading everything after a couple days off, for the Adobe cf summit east in DC this week).

In the very first code example, the filenwas in your user's folder. The reason cf says the file does not exist could be simply that the user running cf does not have permission to access that user folder.

Did you ever run that code bkbk sent, which added a fileexists check? You said in reply you got an error, but you didn't say where  Was it on the filexists function? If so, perhaps cf fails (rather than the filexists check returning false) when the folder named is inaccessible to cf.

So, what user is running cf? If it's running as  windows service, you can see that in the windows services page, or you can see it in the cf admin's "settings summary" page. If it's not the local "system" account, then perhaps that user does not have access to your own "users" folder.

Then, moving on to using cffile upload, you have never shown the code you implemented, especially where the upload destination was. Please show us that and tell us where you NOW get the error (with that code). It may still be a permissions issue, in that perhaps cf does not let the cffile UPLOAD WRITE to the named destination.

/Charlie (troubleshooter, carehart. org)
iccsiAuthor
Inspiring
April 12, 2019

Thanks a million for the message,

The file is on My Document folder, so I do have access to the file and I can open the file using Windows Explorer.

I did use BKBK code and fileexist function return the file does not exist mesage,

BKBK is correct that there are 3 machines, client machine, ColdFusion Server and FTP server, so I use BKBK suggestion to use CFFILE UPLOAD and CFFTP PutFile then works,

Thanks again for helping,

Regards,

Iccsi

Charlie Arehart
Community Expert
Community Expert
April 10, 2019

If you look in your CF logs, you may see more detail on the error, which may help us help you.

But on the surface, shouldn't the first line of code have quotes around the URL? Without it, I wonder if either that line or the CFFTP line referring to it may be what are complaining. That's where knowing the real line in error and error message (hopefully in the CF log) would provide needed clarification.

/Charlie (troubleshooter, carehart. org)
BKBK
Community Expert
Community Expert
April 10, 2019

Well spotted, Charlie Arehart

I had missed that because of the error: "(The system cannot find the path specified)".

If ColdFusion had got that far, then the quotes would probably have been there. I am curious what  iccsi​ has to say about this.

BKBK
Community Expert
Community Expert
April 9, 2019

<cfset ftpurl="ftp.myserver.com"><!---Thanks to Charlie Arehart --->

<cfset ftpusername="myusername">

<cfset ftppassword="mypassowrd">

<cfset ftplocal="C:\Users\MyUser\Documents\MyFile.txt">

<cfset ftpremote="MyFile.txt">

<!--- Open the connection --->

<cfftp action = "open"

username = "#ftpusername#"

password = "#ftppassword#"

connection = "myConnection"

server = "#ftpurl#"

stopOnError = "Yes">

<p>Did opening the connection succeed? <cfoutput>#cfftp.succeeded#</cfoutput>

<!--- Put the file--->

<cfftp connection = "myConnection"

name = "myFile"

action = "PutFile"

localFile="#ftplocal#"

remoteFile="#ftpremote#"

failifexists="no"

passive = "Yes">

<p>Close the connection</p>

<cfftp action = "close"

connection = "myConnection"

stopOnError = "Yes">

<p>Did closing it succeed? <cfoutput>#cfftp.succeeded#</cfoutput>

iccsiAuthor
Inspiring
April 10, 2019

I follow your Charlie Arehart example code, I still get same error,

(The system cannot find the path specified)

Regards,

Iccsi

Inspiring
April 9, 2019

Have you tried setting an absolute path for the remote file?

Community Expert
April 9, 2019

One way I like to diagnose problems like this is to use something like Wireshark to track traffic between the client and the server. This should let you know more about what the two machines are saying to each other. If you have logging as an option on the FTP server, you might be able to get that information that way, instead.

Dave Watts, Eidolon LLC

Dave Watts, Eidolon LLC