Rename file until get file from a host with Fabric
up vote
0
down vote
favorite
I am getting files from a host that will be consumed for another system. I realized I need to rename the files while it is being downloading from the remote server to avoid data corruption. Do you know if there is a way to achieve it, maybe the get()
function in combination with StringIO ? or is not possible with fabric?
Edited: Please have a sample of my code.
# ~/fabfile.py
from fabric.api import task, env, run, settings, cd, put, get, execute
@task
def send_files():
'''
Send the downloaded files (found.txt) from remote to the server
'''
# Get the sorted list of filenames (to send the files in order)
with settings(war_only=True):
with cd(REMOTE_DIR):
sorted_list = sort_files()
for file in sorted_list:
print(file)
file = file.replace('n', '')
#Something here to change the extension
#when the download is complete change to the original extension
# Example
# get 427783.zip
# change to 427783.crdownload
# back to 427783.zip when is done.
get(REMOTE_DIR + DESTINATION + '/' + file, INPUT_FOLDER + '\' + file)
I think I have to re-do my question: I would like to know when the download is completed using fabric ftp connection and the get() method, another service will pick up the file and would like to avoid the download is not completed yet.
python file-io fabric
add a comment |
up vote
0
down vote
favorite
I am getting files from a host that will be consumed for another system. I realized I need to rename the files while it is being downloading from the remote server to avoid data corruption. Do you know if there is a way to achieve it, maybe the get()
function in combination with StringIO ? or is not possible with fabric?
Edited: Please have a sample of my code.
# ~/fabfile.py
from fabric.api import task, env, run, settings, cd, put, get, execute
@task
def send_files():
'''
Send the downloaded files (found.txt) from remote to the server
'''
# Get the sorted list of filenames (to send the files in order)
with settings(war_only=True):
with cd(REMOTE_DIR):
sorted_list = sort_files()
for file in sorted_list:
print(file)
file = file.replace('n', '')
#Something here to change the extension
#when the download is complete change to the original extension
# Example
# get 427783.zip
# change to 427783.crdownload
# back to 427783.zip when is done.
get(REMOTE_DIR + DESTINATION + '/' + file, INPUT_FOLDER + '\' + file)
I think I have to re-do my question: I would like to know when the download is completed using fabric ftp connection and the get() method, another service will pick up the file and would like to avoid the download is not completed yet.
python file-io fabric
Can you be more specific and maybe post your code?
– Peshmerge
Nov 12 at 12:34
@Peshmerge Yes, please check the code I just add, hope it can give you a better idea. Thank you so much.
– Sora
Nov 13 at 1:52
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am getting files from a host that will be consumed for another system. I realized I need to rename the files while it is being downloading from the remote server to avoid data corruption. Do you know if there is a way to achieve it, maybe the get()
function in combination with StringIO ? or is not possible with fabric?
Edited: Please have a sample of my code.
# ~/fabfile.py
from fabric.api import task, env, run, settings, cd, put, get, execute
@task
def send_files():
'''
Send the downloaded files (found.txt) from remote to the server
'''
# Get the sorted list of filenames (to send the files in order)
with settings(war_only=True):
with cd(REMOTE_DIR):
sorted_list = sort_files()
for file in sorted_list:
print(file)
file = file.replace('n', '')
#Something here to change the extension
#when the download is complete change to the original extension
# Example
# get 427783.zip
# change to 427783.crdownload
# back to 427783.zip when is done.
get(REMOTE_DIR + DESTINATION + '/' + file, INPUT_FOLDER + '\' + file)
I think I have to re-do my question: I would like to know when the download is completed using fabric ftp connection and the get() method, another service will pick up the file and would like to avoid the download is not completed yet.
python file-io fabric
I am getting files from a host that will be consumed for another system. I realized I need to rename the files while it is being downloading from the remote server to avoid data corruption. Do you know if there is a way to achieve it, maybe the get()
function in combination with StringIO ? or is not possible with fabric?
Edited: Please have a sample of my code.
# ~/fabfile.py
from fabric.api import task, env, run, settings, cd, put, get, execute
@task
def send_files():
'''
Send the downloaded files (found.txt) from remote to the server
'''
# Get the sorted list of filenames (to send the files in order)
with settings(war_only=True):
with cd(REMOTE_DIR):
sorted_list = sort_files()
for file in sorted_list:
print(file)
file = file.replace('n', '')
#Something here to change the extension
#when the download is complete change to the original extension
# Example
# get 427783.zip
# change to 427783.crdownload
# back to 427783.zip when is done.
get(REMOTE_DIR + DESTINATION + '/' + file, INPUT_FOLDER + '\' + file)
I think I have to re-do my question: I would like to know when the download is completed using fabric ftp connection and the get() method, another service will pick up the file and would like to avoid the download is not completed yet.
python file-io fabric
python file-io fabric
edited Nov 21 at 1:54
asked Nov 12 at 3:03
Sora
458
458
Can you be more specific and maybe post your code?
– Peshmerge
Nov 12 at 12:34
@Peshmerge Yes, please check the code I just add, hope it can give you a better idea. Thank you so much.
– Sora
Nov 13 at 1:52
add a comment |
Can you be more specific and maybe post your code?
– Peshmerge
Nov 12 at 12:34
@Peshmerge Yes, please check the code I just add, hope it can give you a better idea. Thank you so much.
– Sora
Nov 13 at 1:52
Can you be more specific and maybe post your code?
– Peshmerge
Nov 12 at 12:34
Can you be more specific and maybe post your code?
– Peshmerge
Nov 12 at 12:34
@Peshmerge Yes, please check the code I just add, hope it can give you a better idea. Thank you so much.
– Sora
Nov 13 at 1:52
@Peshmerge Yes, please check the code I just add, hope it can give you a better idea. Thank you so much.
– Sora
Nov 13 at 1:52
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
Using wget
will solve your problem. You can do the following:
with connection(host=host, user=user) as c:
save_path = '/var/www/new_name.extension'
source_path = 'where_your_file_resides'
c.run('wget -p -O %s %s' %(save_path, source_path)
Please correct me if I am wrong, in my code file_path_you_want_to_download will be the path where I want to store the file when downloaded, in my code INPUT_FOLDER, right?
– Sora
Nov 13 at 13:55
Please check my edit!
– Peshmerge
Nov 13 at 14:19
I try your code, however I think it does not work because the file resides in the same server I connect to. wget is not for external url?
– Sora
Nov 20 at 7:02
add a comment |
up vote
0
down vote
I did not find any suitable example to change the extension automatically when the downloading is still in process. So, I figured it out and download the file with another a temporary extension, once the get() function finish fabric will execute the next command, so I take advantage of this and rename the file.
Like this:
def rename_file(original, output):
try:
os.rename(original, output)
except WindowsError:
os.remove(output)
os.rename(original, output)
@task
def send_files():
with settings(war_only=True):
with cd(REMOTE_DIR):
sorted_list = sort_files()
for file in sorted_list:
old_file = REMOTE_DIR + DESTINATION + '/' + file
temp_file = INPUT_OTDF_FOLDER + '\' + file + '.tmp'
get(old_file, temp_file)
rename_file(temp_file, new_file)
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Using wget
will solve your problem. You can do the following:
with connection(host=host, user=user) as c:
save_path = '/var/www/new_name.extension'
source_path = 'where_your_file_resides'
c.run('wget -p -O %s %s' %(save_path, source_path)
Please correct me if I am wrong, in my code file_path_you_want_to_download will be the path where I want to store the file when downloaded, in my code INPUT_FOLDER, right?
– Sora
Nov 13 at 13:55
Please check my edit!
– Peshmerge
Nov 13 at 14:19
I try your code, however I think it does not work because the file resides in the same server I connect to. wget is not for external url?
– Sora
Nov 20 at 7:02
add a comment |
up vote
0
down vote
Using wget
will solve your problem. You can do the following:
with connection(host=host, user=user) as c:
save_path = '/var/www/new_name.extension'
source_path = 'where_your_file_resides'
c.run('wget -p -O %s %s' %(save_path, source_path)
Please correct me if I am wrong, in my code file_path_you_want_to_download will be the path where I want to store the file when downloaded, in my code INPUT_FOLDER, right?
– Sora
Nov 13 at 13:55
Please check my edit!
– Peshmerge
Nov 13 at 14:19
I try your code, however I think it does not work because the file resides in the same server I connect to. wget is not for external url?
– Sora
Nov 20 at 7:02
add a comment |
up vote
0
down vote
up vote
0
down vote
Using wget
will solve your problem. You can do the following:
with connection(host=host, user=user) as c:
save_path = '/var/www/new_name.extension'
source_path = 'where_your_file_resides'
c.run('wget -p -O %s %s' %(save_path, source_path)
Using wget
will solve your problem. You can do the following:
with connection(host=host, user=user) as c:
save_path = '/var/www/new_name.extension'
source_path = 'where_your_file_resides'
c.run('wget -p -O %s %s' %(save_path, source_path)
edited Nov 13 at 14:17
answered Nov 13 at 13:30
Peshmerge
264317
264317
Please correct me if I am wrong, in my code file_path_you_want_to_download will be the path where I want to store the file when downloaded, in my code INPUT_FOLDER, right?
– Sora
Nov 13 at 13:55
Please check my edit!
– Peshmerge
Nov 13 at 14:19
I try your code, however I think it does not work because the file resides in the same server I connect to. wget is not for external url?
– Sora
Nov 20 at 7:02
add a comment |
Please correct me if I am wrong, in my code file_path_you_want_to_download will be the path where I want to store the file when downloaded, in my code INPUT_FOLDER, right?
– Sora
Nov 13 at 13:55
Please check my edit!
– Peshmerge
Nov 13 at 14:19
I try your code, however I think it does not work because the file resides in the same server I connect to. wget is not for external url?
– Sora
Nov 20 at 7:02
Please correct me if I am wrong, in my code file_path_you_want_to_download will be the path where I want to store the file when downloaded, in my code INPUT_FOLDER, right?
– Sora
Nov 13 at 13:55
Please correct me if I am wrong, in my code file_path_you_want_to_download will be the path where I want to store the file when downloaded, in my code INPUT_FOLDER, right?
– Sora
Nov 13 at 13:55
Please check my edit!
– Peshmerge
Nov 13 at 14:19
Please check my edit!
– Peshmerge
Nov 13 at 14:19
I try your code, however I think it does not work because the file resides in the same server I connect to. wget is not for external url?
– Sora
Nov 20 at 7:02
I try your code, however I think it does not work because the file resides in the same server I connect to. wget is not for external url?
– Sora
Nov 20 at 7:02
add a comment |
up vote
0
down vote
I did not find any suitable example to change the extension automatically when the downloading is still in process. So, I figured it out and download the file with another a temporary extension, once the get() function finish fabric will execute the next command, so I take advantage of this and rename the file.
Like this:
def rename_file(original, output):
try:
os.rename(original, output)
except WindowsError:
os.remove(output)
os.rename(original, output)
@task
def send_files():
with settings(war_only=True):
with cd(REMOTE_DIR):
sorted_list = sort_files()
for file in sorted_list:
old_file = REMOTE_DIR + DESTINATION + '/' + file
temp_file = INPUT_OTDF_FOLDER + '\' + file + '.tmp'
get(old_file, temp_file)
rename_file(temp_file, new_file)
add a comment |
up vote
0
down vote
I did not find any suitable example to change the extension automatically when the downloading is still in process. So, I figured it out and download the file with another a temporary extension, once the get() function finish fabric will execute the next command, so I take advantage of this and rename the file.
Like this:
def rename_file(original, output):
try:
os.rename(original, output)
except WindowsError:
os.remove(output)
os.rename(original, output)
@task
def send_files():
with settings(war_only=True):
with cd(REMOTE_DIR):
sorted_list = sort_files()
for file in sorted_list:
old_file = REMOTE_DIR + DESTINATION + '/' + file
temp_file = INPUT_OTDF_FOLDER + '\' + file + '.tmp'
get(old_file, temp_file)
rename_file(temp_file, new_file)
add a comment |
up vote
0
down vote
up vote
0
down vote
I did not find any suitable example to change the extension automatically when the downloading is still in process. So, I figured it out and download the file with another a temporary extension, once the get() function finish fabric will execute the next command, so I take advantage of this and rename the file.
Like this:
def rename_file(original, output):
try:
os.rename(original, output)
except WindowsError:
os.remove(output)
os.rename(original, output)
@task
def send_files():
with settings(war_only=True):
with cd(REMOTE_DIR):
sorted_list = sort_files()
for file in sorted_list:
old_file = REMOTE_DIR + DESTINATION + '/' + file
temp_file = INPUT_OTDF_FOLDER + '\' + file + '.tmp'
get(old_file, temp_file)
rename_file(temp_file, new_file)
I did not find any suitable example to change the extension automatically when the downloading is still in process. So, I figured it out and download the file with another a temporary extension, once the get() function finish fabric will execute the next command, so I take advantage of this and rename the file.
Like this:
def rename_file(original, output):
try:
os.rename(original, output)
except WindowsError:
os.remove(output)
os.rename(original, output)
@task
def send_files():
with settings(war_only=True):
with cd(REMOTE_DIR):
sorted_list = sort_files()
for file in sorted_list:
old_file = REMOTE_DIR + DESTINATION + '/' + file
temp_file = INPUT_OTDF_FOLDER + '\' + file + '.tmp'
get(old_file, temp_file)
rename_file(temp_file, new_file)
answered Nov 22 at 3:48
Sora
458
458
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255457%2frename-file-until-get-file-from-a-host-with-fabric%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you be more specific and maybe post your code?
– Peshmerge
Nov 12 at 12:34
@Peshmerge Yes, please check the code I just add, hope it can give you a better idea. Thank you so much.
– Sora
Nov 13 at 1:52