Hello,
I would like to share with you something that an user has just asked me by email. He wanted a script to constantly check for the file or files that may appear on a local folder and as soon as they are found. I wrote this small script for him:
I would like to share with you something that an user has just asked me by email. He wanted a script to constantly check for the file or files that may appear on a local folder and as soon as they are found. I wrote this small script for him:
FTP Script
- #
- # This script looks for files to appear in a
- # specific local directory and uploads them
- # to the FTP server. Once uploaded it moves
- # the files to another directory
- #
- # You can schedule this script to be run every
- # 5 minutes to automatically upload every file
- # that is copied to the folder
- #
- # The directory to watch for files
- $incoming_dir="C:\files_appear_here"
- # Once the files are uploaded they are copied to here
- $processed_files_dir="C:\uploaded_files"
- # Connect to the FTP server
- # Change current local directory
- # Retrieve the C:\pim\outbox file listing
- # If GETLIST failed stop the script
- # Upload the file
- # If the file has been succesfully uploaded
- # move it
liked Script FTP? Try our other product Email Parser
Be aware that you may upload a partial file if the file is in the process of "appearing" in "C:\files_appear_here".
And the timing might just be right to upload a partial file, have the "appearance" finish during the upload, then move the completed file to the "C:\uploaded_files" directory.
Which is why I did an OS file move first, and then uploaded the file. (See Store and Forward)
Edited by ScriptFTP support. You can see the script that Bucket posted here:
http://www.scriptftp.com/forum/viewtopic.php?p=1300
And the timing might just be right to upload a partial file, have the "appearance" finish during the upload, then move the completed file to the "C:\uploaded_files" directory.
Which is why I did an OS file move first, and then uploaded the file. (See Store and Forward)
Edited by ScriptFTP support. You can see the script that Bucket posted here:
http://www.scriptftp.com/forum/viewtopic.php?p=1300
Be aware that you may upload a partial file if the file is in the process of "appearing" in "C:\files_appear_here".You are absolutely right Bucket. I come across another solution a bit simpler than try moving the file to see if the file is being written by another process or being copied: check the file size, wait one second, and check the file size gain. If the file sizes are different it means that the file is being written (or in the process of "appearing" in that folder). The drawback of this solution is that it takes one second for every file to be uploaded. Of course, the other solution you posted (the link is in the previous post on this forum thread) is also completely correct.
FTP Script
- #
- # This script looks for files to appear in a
- # specific local directory and uploads them
- # to the FTP server. Once uploaded it moves
- # the files to another directory
- #
- # You can schedule this script to be run every
- # 5 minutes to automatically upload every file
- # that is copied to the folder
- #
- # The directory to watch for files
- $incoming_dir="C:\files_appear_here"
- # Once the files are uploaded they are copied to here
- $processed_files_dir="C:\uploaded_files"
- # Connect to the FTP server
- # If the connection has failed wait 5 seconds and close ScriptFTP
- # Change current local directory
- # If cannot change current local directory wait 5 seconds and close ScriptFTP
- # Retrieve the C:\pim\outbox file listing
- # If cannot get the file listing wait 5 seconds and close ScriptFTP
- # Check the file size
- # Wait for 1 second and check the file size again
- # Check the file size
- # Upload the file if the file is not being written (sizes are equal)
- # and check also that GETFILESIZE did not returned an error (negative value)
- # Upload the file
- # If the file has been succesfully
- # uploaded move it to the other dir
- # Close the connection
liked Script FTP? Try our other product Email Parser
Hello!
I'm looking for a FTP-program that can help me monitor a number of folders (right now about 20). When a .csv file appers a folder, I want it uploaded to an FTP-server (different servers and logins for each folder).
I think that the ScriptFTP and the script in this thread is close to what I'm looking for. But it worries me a bit that the script opens a connection even before it checks if there is anything to transmit. In my case there could be many unnessecary connections. So I would like a script like this, but that only opens a connection when something to transmit is found in the local folder.
Would it be OK to move the "OPENHOST" and CLOSEHOST to inside the IF($size1==$size2 AND $size1>=0 AND $size2>=0)... ...ENDIF? (Usually there will be only one .csv file to transmit).
I'm looking for a FTP-program that can help me monitor a number of folders (right now about 20). When a .csv file appers a folder, I want it uploaded to an FTP-server (different servers and logins for each folder).
I think that the ScriptFTP and the script in this thread is close to what I'm looking for. But it worries me a bit that the script opens a connection even before it checks if there is anything to transmit. In my case there could be many unnessecary connections. So I would like a script like this, but that only opens a connection when something to transmit is found in the local folder.
Would it be OK to move the "OPENHOST" and CLOSEHOST to inside the IF($size1==$size2 AND $size1>=0 AND $size2>=0)... ...ENDIF? (Usually there will be only one .csv file to transmit).
Transfer to the script folder name, server address, user name and password as parameters on the command line. And create 20 jobs in the scheduler.
FTP Script
- #
- # This script looks for *.csv files to appear
- # in a specific local directory and uploads
- # them to the FTP server. Once uploaded it moves
- # the files to another directory
- #
- # You can schedule this script to be run every
- # 5 minutes to automatically upload every *.csv
- # file that is copied to the folder
- #
- # Use:
- # ScriptFTP.exe script_file.ftp incoming_dir processed_files_dir server user pass
- # The directory to watch for files
- # Once the files are uploaded they are copied to here
- # Change current local directory
- # If cannot change current local directory wait 5 seconds and close ScriptFTP
- # Retrieve the incoming_dir *.csv file listing
- # If cannot get the file listing wait 5 seconds and close ScriptFTP
- # If file list is empty wait 5 seconds and close ScriptFTP
- # Connect to the FTP server
- # If the connection has failed wait 5 seconds and close ScriptFTP
- # Check the file size
- # Wait for 1 second and check the file size again
- # Check the file size
- # Upload the file if the file is not being written (sizes are equal)
- # and check also that GETFILESIZE did not returned an error (negative value)
- # Upload the file
- # If the file has been succesfully
- # uploaded move it to the other dir
- # Close the connection
I am wanting to do a similar but opposite thing.
Is there a way to download a file once it has appeared in a remote folder?
I am sure it would require some sort of "listen" function.
Even checking every 10 mins would be sufficient.
Is there a way to download a file once it has appeared in a remote folder?
I am sure it would require some sort of "listen" function.
Even checking every 10 mins would be sufficient.
Hi Tim. Thanks for pointing this out, it helped a lot.
I have replied your last post with this script modified:
http://www.scriptftp.com/forum/general-f6/upload-a-file-as-soon-as-it-appears-t520.html
I have replied your last post with this script modified:
http://www.scriptftp.com/forum/general-f6/upload-a-file-as-soon-as-it-appears-t520.html
liked Script FTP? Try our other product Email Parser
- All times are UTC -