Copy link to clipboard
Copied
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
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
...Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thanks friend,
This was the answer of a wise man. But I have a couple of points to make:
Thanks a lot and I still hope that anything else comes up that would give me the first option.
Thanks...
Copy link to clipboard
Copied
To get files from a client to your server, cffile is the tag you want, not cfftp.
Copy link to clipboard
Copied
Dan, I think Yannis's intention is to upload from his Coldfusion server to an FTP server. He is to be the client.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
@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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Yannis, I am experimenting with what might be a passable way to upload the directory in one fell swoop. Fingers crossed.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Yannis, don't fall for it. Adam Cameron and BKBK are actually one and the same person!
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
@Yannis Develekos
cfftp upload folder with subfolders in a single operation.
Was my last post a possible solution?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Very kind of you to update us. Much appreciated.