Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

cfftp upload folder with subfolders in a single operation.

Explorer ,
Jan 23, 2010 Jan 23, 2010

Hi everybody,

I have a folder full of subfolders with images in them and I want to upload them to an ftp server. Is this possible to instruct coldfusion to upload this folder with all its sublfolders and contents?

Thank you in advance,

Yannis

5.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jan 24, 2010 Jan 24, 2010

The thing is, with recursion, one doesn't need to worry about any level of the hierarchy other than the "current" one, and then making the recursive call at the right point.  The act of recursing sorts out the rest of it automatically.

One trap I have seen people getting bogged down with when attempted something recursive is that they try to hold the entire "end result" in their heads (like traversing the sub-sub-sub-dirs), whereas there's simply no need.  One only ever has to focus on getting on

...
Translate
Community Expert ,
Jan 23, 2010 Jan 23, 2010

Yes, it is possible to use Coldfusion's cfftp tag to create directories on the FTP server, and then upload the files into them. However, the code is likely to be complicated, as subfolders imply recursion.

Why bother with Coldfusion?  FileZilla is specialist FTP software that would do it for you, as easy as one, two, three, leaving you ample time for beer. Furthermore, it is open-source and free.

If FileZilla makes you happy, think of the poor bugger burning the candle at both ends while others are having their beer. Go to the site and donate.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 23, 2010 Jan 23, 2010

Thanks friend,

This was the answer of a wise man. But I have a couple of points to make:

  1. I new that it was complicated and that's why I did not want to implement it that way. I hoped that I missed something and there was a simple way to copy the complete folder structure along with contents in a simple step.
  2. I wish to give the client a completely transparent experience so that he will not need to use an ftp client as you suggested. But that's what I may end up doing.

Thanks a lot and I still hope that anything else comes up that would give me the first option.

Thanks...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 23, 2010 Jan 23, 2010

To get files from a client to your server, cffile is the tag you want, not cfftp.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 23, 2010 Jan 23, 2010

Dan, I think Yannis's intention is to upload from his Coldfusion server to an FTP server. He is to be the client.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 24, 2010 Jan 24, 2010

This is correct. I'm using Coldfusion server to run a couple of modifications to a large number of images (resize twice to create large copies and thumbs, apply watermark to both...), then I need to upload them to an ftp server. So I believe that cfftp is the one to do the job but I could not find a way to instruct cfftp to recreate the folder structure on the remote ftp server without running endless lines of code.

Of course any new ideas will still be welcomed.

Thanks,

Yannis

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 24, 2010 Jan 24, 2010

In that case, a combination of cfdirectory, isDirectory, and cfftp is what you want.  As BKBK mentioned, it will be complicated because for each directory you find, you will have to travel down it until you find no more subdirectories.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 24, 2010 Jan 24, 2010

How is it complicated?

1) call a function, passing in a dir

2) grab a dir listing

3) iterate over it

4) if the current item is a file: FTP it

5) if the current item is a dir:

a) create the remote dir

b) call the function again, passing in the new dir

Obviously some detail needs adding there, but those are the basic steps.

Bear in mind that FTPing a file has quite a bit of static overhead (FTPing a big file or a small file has the same overhead).  Often it's better to zip the files up and FTP the zip, rather than FTPing heaps of individual files.  Doing it the zip/FTP way requires being able to unzip at the remote end though.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2010 Jan 24, 2010

Question:

How is it complicated?

Answer: Here's how

1) call a function, passing in a dir

2) grab a dir listing

3) iterate over it

4) if the current item is a file: FTP it

5) if the current item is a dir:

a) create the remote dir

b) call the function again, passing in the new dir

Obviously some detail needs adding there, but those are the basic steps.

Bear in mind that FTPing a file has quite a bit of static overhead (FTPing a big file or a small file has the same overhead).  Often it's better to zip the files up and FTP the zip, rather than FTPing heaps of individual files.  Doing it the zip/FTP way requires being able to unzip at the remote end though.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 24, 2010 Jan 24, 2010

Question:

How is it complicated?

Answer: Here's how

[etc]

You and I have very different ideas of what constitute's "complicated".

Despite the fact the procedure has only seven steps, from start to finish arrive at said procedure took me less time than it took to write it down.

And what is actually complicated about a process containing two function calls, a loop and a conditional statement?

Or is this just you being obtuse / boorish again (and, yes, I could answer that question for you again, with probably a more accurate answer - "yes" - than you would be able to muster).

WTF is wrong with you?

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2010 Jan 24, 2010
You and I have very different ideas of what constitute's "complicated".

That's all right. However, you can say what you wish to say, without your usual habit of first denigrating the previous speaker.

Despite the fact the procedure has only seven steps, from start to finish arrive at said procedure took me less time than it took to write it down. And what is actually complicated about a process containing two function calls, a loop and a conditional statement?

It would be complicated, relatively speaking, if a much simpler solution could be found.

Or is this just you being obtuse / boorish again (and, yes, I could answer that question for you again, with probably a more accurate answer - "yes" - than you would be able to muster).

You don't have to lash about and to continually emphasize your prowess at accurate answers. If your answer is accurate, then let it speak for itself.

WTF is wrong with you?

That's funny. I was just about to ask you that, too.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2010 Jan 24, 2010

@Yannis

I believe that cfftp is the one to do the job but I could not find a way to instruct cfftp to recreate the folder structure on the remote ftp server without running endless lines of code.

Of course any new ideas will still be welcomed.

That's the challenge Yannis has put before us. It'd be good for everyone to have such a solution, if it exists.

Dunno if this would help what you're doing: http://www.zehon.com/features_ftp.htm.
Shouldn't be too hard to wrap that up in CF.  Never used it, mind, just googled it up.

Thanks.  Jaw-jaw, not war-war, as Churchill said.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 24, 2010 Jan 24, 2010

Regarding:

How is it complicated?

For me, the complicated part is sub-sub-sub-subdirectories and getting back along the same path you came in on without missing anything.  If this were my task, that's what I would see as the biggest challenge.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 24, 2010 Jan 24, 2010

The thing is, with recursion, one doesn't need to worry about any level of the hierarchy other than the "current" one, and then making the recursive call at the right point.  The act of recursing sorts out the rest of it automatically.

One trap I have seen people getting bogged down with when attempted something recursive is that they try to hold the entire "end result" in their heads (like traversing the sub-sub-sub-dirs), whereas there's simply no need.  One only ever has to focus on getting one tier of that right, and then call the function itself again to process the next tier.  All the nesting is handled / processed automatically by the recursion.  I guess the trick is to be able to be clear in one's head what needs to be passed into the function - from any arbitrary point - to be fully capable of processing a single tier, and how to take that info and process it in such a way as to derive the information necessary for the next tier.

I guess with this requirement one needs to pass in the base file system dir, as well as the base FTP dir.  Subsequent recursive "base" dirs can be contrived simply by appending a subdir's name onto the current base dirs and passing the result into the recursive function call.

To save needing to use recursion, one could use the <cfdirectory> tag's inbuilt recursive functionality, then doing a flat iteration over that recordset, using the paths from each record to contrive the FTP subdir.  Then either creating the remote dir (if the current records is a dir), or FTPing the file (if it's a file).

Not really the one-fell-swoop BKBK is promising, but surely... not that complicated (although I hesitate to suggest such notions now).

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2010 Jan 24, 2010

Yannis, I am experimenting with what might be a passable way to upload the directory in one fell swoop. Fingers crossed.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 24, 2010 Jan 24, 2010

Yannis, I am experimenting with what might be a passable way to upload the directory in one fell swoop. Fingers crossed.

Dunno if this would help what you're doing: http://www.zehon.com/features_ftp.htm.

Shouldn't be too hard to wrap that up in CF.  Never used it, mind, just googled it up.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 24, 2010 Jan 24, 2010

Gentlemen,

Please do not turn this into a fight. You seem to be both experienced developers willing to help anyone who seeks for help. I have to say that the information you both provide is really helpful for me in some way. And it proves that you are both right at the same time so there is really not need to argue.

For example, the solution suggested is not really “complicated”. I agree. But I also agree with the statement that if there is a simpler solution available, so this might prove to be complicated indeed. You see, you are both correct at the same time.

Allow me to say that in order to provide helpful answers it is important for us to react calmly and gently.

Thank you all for your ideas so far. It seems that we will indeed come up with a way to accomplish this really easily.

Yannis

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 24, 2010 Jan 24, 2010
Please do not turn this into a fight.

There is no fight. BKBK has a habit of being unnecessarily obtuse; I have a habit of calling him/her on it.  BKBK reacts to that.  I roll my eyes in despair and move on (OK, sometimes not immediately ;-).

Of course you're right in that I should not rise to the original obtuse... err... -ness.  Obtusitude.  Obtusicity.  Whatever.  It's a pointless waste of time, and a bit mean-spirited of me.  Oh well.

At the end of the day the problems usually get solved, which is the main thing.  We just provide a sideshow too 😉

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2010 Jan 24, 2010

Yannis, don't fall for it. Adam Cameron and BKBK are actually one and the same person!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 24, 2010 Jan 24, 2010

BKBK wrote:

Yannis, don't fall for it. Adam Cameron and BKBK are actually one and the same person!

Hahahahahahahahahahahahah.  Nice.

Now that's a scary thought.  No doubt for both of us.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2010 Jan 24, 2010

Yannis, here is a solution for batch FTP upload for you. It is indeed the one Adam referred to, from http://www.zehon.com.

Go to the zehon.com download page. Download the file zehon_transfer_pack-1.1.zip (for JDK 1.5 or above).

Stop Coldfusion.

Extract the contents of the zehon zip file to the lib directory of your Coldfusion installation. That is, to {Coldfusion_installation_dir}/lib/.

Important: You will find that the Coldfusion lib directory

    already contains JAR files sharing the same name

    as 5 or 6 of the zehon JAR files. This is because

    Coldfusion and zehon share the same logging framework.

    Do NOT overwrite any JAR files already present in Coldfusion!

    That is even unnecessary.

Restart Coldfusion.

Run the following code as a CFM page:

<cfscript>

//FTP server

host = "members.domain.com";

username = "bkbk";

password = "b1k2";

/* sendingFolder = Folder whose content is to be uploaded recursively

*  to the FTP server.

*  Note: it is the content of my testUpload folder that is uploaded, not

*  the folder itself. If you wish to FTP testUpload and its

*  contents, then simply copy the testUpload directory into ftpDir, for

*  example, and use "C:\Documents and Settings\BKBK\Desktop\ftpDir"

*  instead as sendingFolder.

*/

sendingFolder = "C:\Documents and Settings\BKBK\Desktop\testUpload";

/* Forward slash / = root dir of FTP server.

*  if you wish to FTP to privateDir under the root, for example,

*  then set destFolder to "/privateDir"

*/

destFolder = "/";

FTP = createObject("java", "com.zehon.ftp.FTP");

thisBatchTransferProgressDefault= createObject("java", "com.zehon.BatchTransferProgressDefault").init();

FileTransferStatus = createObject("java", "com.zehon.FileTransferStatus");

try {

   status = FTP.sendFolder(sendingFolder, destFolder, thisBatchTransferProgressDefault, host, username, password);

    if(FileTransferStatus.SUCCESS is status){

        writeOutput(sendingFolder & " got ftp-ed successfully to folder " & destFolder);

    }

    else if(FileTransferStatus.FAILURE is status){

        writeOutput("Failed to ftp to folder " & destFolder);

    }

} catch (any e) {

   writeOutput(e.message);

}   

</cfscript>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 27, 2010 Jan 27, 2010

@Yannis Develekos

cfftp upload folder with subfolders in a single operation.

Was my last post a possible solution?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 27, 2010 Jan 27, 2010

I will get back on this project on Monday. Of course whatever the solution will be I will let you know. I never forget to do that .

Thanks,

Yannis

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 11, 2010 Feb 11, 2010

Jentlemen,

I just wanted to point out the fact that I never finished this. So this is the reason why I did not provide you with feedback so far. Anyway I will have to complete this project any day soon and I will let you know about the results.

Thank you all,

Yannis

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 11, 2010 Feb 11, 2010

Very kind of you to update us. Much appreciated.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources