Linux implementation file uploads ftp server script code

  • 2020-06-12 11:17:55
  • OfStack

During the work, every time the file is uploaded to ftp server, ip, user name, password, etc., need to be entered manually. Therefore, consider writing scripts to complete the upload of the file. The specific script sync. sh is as follows:


#!/bin/bash

source ~/.bashrc

#  Simulation to enter ftp Command line mode, where EOF Represents the exit marker 
ftp -niv <<- EOF

#  According to the ftp the ip Address and port number, connect ftp The server 
open ip port

#  Enter the username and password 
user userName password

#  In order to bin Mode for transmission, and ASCII Patterns are different to use bin Modules can prevent messy code problems 
bin

#  Upload a file 
get $1

#  The end of the 
bye
# exit 
EOF

Then add the script sync. sh to the environment variable and only need to execute sync. sh filename each time. The specific execution process is as follows:


Connected to *.*.*.*.
220 Microsoft FTP Service
331 Password required for userName.
230 User logged in.
Remote system type is Windows_NT.
200 Type set to I.
local: filename remote: filename
200 PORT command successful.
125 Data connection already open; Transfer starting.
226 Transfer complete.
112089125 bytes received in 44.62 secs (2453.3 kB/s)
221 Goodbye.

Related articles: