Sending file to server via FTP via linux command line

Asked

Viewed 2,077 times

1

Good morning. I have some doubts regarding a project I’m finishing using linux ( I don’t have much domain ).

I have a program written in C that generates files. txt, I must make this program run every day ( until then, I know I must use crontab ). After this file is generated I must send it to a server via FTP. At this point do not know how to proceed, given that I must access the directory that the file was generated, open connection with FTP and upload it.

Another question I’m having is, what is the advantage of using an upload to a server through the FTP protocol?

Edit 1:

I performed the script and until then it works when I step in the file variable the file-source and source-file, however it is necessary to declare a new name, and I would just like to duplicate the files from one place to another.

Follows script:

#!/bin/bash
HOST='192.168.8.151'
usuario='ftp_tentativas'
senha='passwdwillian01'
arquivo='/var/www/html/log/Export/*.csv'

ftp -n $HOST <<END_SCRIPT
user ${usuario} ${senha}

cd recebe
put $arquivo
cp /var/www/html/log/Export/*.* /var/www/html/log/Enviados/.
rm /var/www/html/log/Export/*.* 

quit
END_SCRIPT
exit 0

Error showing:

?Invalid command
Could not create file.
Remove directory operation failed.

When done 'by hand' directly by the console it shows the destination equal to the source, not creating the file correctly.

ftp> put /var/www/html/log/Export/*.csv
local: /var/www/html/log/Export/Relatorio_Qualidade_20180730.csv remote: /var/www/html/log/Export/Relatorio_Qualidade_20180730.csv
227 Entering Passive Mode (192,168,8,111,109,45).
553 Could not create file.
  • 1

    I think you are making expensive mess William, the server is server, the server is "not FTP", FTP is a tool installed on the server (and with port released) to facilitate sharing the data between your local machine and another machine, as well as SSH, or even googledrive, but works on a protocol itself (FTP protocol), your server might not have the FTP tool that would still work equally, but you would have to use other methods to upload the files.

  • @Guilhermenascimento, thanks for the return, but I think I did not know how to express myself, the idea was to explain that I want to send the arch to the server by FTP protocol as you said yourself. But I appreciate the feedback and the specification. opened up a little more my mind haha

1 answer

3


first check if you have the FTP client installed on the machine that will run cron: apt-get install ftp -y
# if the distribution is based on debian

you can create scrip will run by cron:

#!/bin/bash
HOST='192.168.8.151'
usuario='ftp_tentativas'
senha='passwdwillian01'

arquivo='*.csv'

cd /var/www/html/log/Export/

ftp -n $HOST <<END_SCRIPT
user ${usuario} ${senha}
prompt
mput $arquivo
quit
END_SCRIPT
cp /var/www/html/log/Export/*.* /var/www/html/log/Enviados/.
rm /var/www/html/log/Export/*.* 
exit 0

Generally FTP protocol is not widely used because it has no encryption, it is usually used SFTP, FTPS.

  • Thanks Anderson. just for a question. when I call the field/path/file is for the file being generated correct? Where I would define where this file should be sent?

  • Ah beauty, understood!

  • Opa blz, just one more question I came up with, I can create this script direct in cron?

  • Oops, got it. Thank you!

  • I have one more question... in the script I did in C I am wanting to perform the following procedure send the file with the name in which it is generated in the folder, after that copy this file to another folder and remove the data from the current one. the script is in question ( edited ) but it returns me some errors ( follow in the edited question too) to perform via put the syntax differs from a 'bash' common?''

Browser other questions tagged

You are not signed in. Login or sign up in order to post.