Ⅰ shell腳本實現定時生成個以當前時間命名的TXT文件,然後ftp上傳到另一台伺服器上,這個怎麼寫啊
#!/bin/bash
#----------請自定義如下內容----------
user=root#FTP用戶名
password=root#密碼
remoteDir=/tmp#遠程伺服器FTP目錄
#------------------------------------
currTime=$(date"+%Y%m%d%H%M%S")
filename=${currTime}.txt
touch$filename
sync
ftp-in<<-EOF
user$user$password
cd$remoteDir
bin
put$filename
bye
EOF
Ⅱ 使用shell腳本批量上傳文件
1、設置ssh無密碼訪問
2、用scp -R ,例如
scp -R /root/tmp root@server:/root
3、或者用rsync命令,例如
#!/bin/sh
/usr/bin/rsync -av '-e ssh -p 22' root@172.16.1.1:/root/tmp /root/
Ⅲ linux下用shell編程FTP上傳文件的問題
Linux下用shell編程實現ftp自動登錄上傳文件,代碼如下:
####把本地/home/databachup/a.shupftp/home/databackup下####
#!/bin/bash
ftp-n<<!
openFTP伺服器IP地址
userFTP賬戶FTP密碼
binary
cd/home/data
lcd/home/databackup
prompt
puta.sha.sh#要上傳的文件
close
bye
!
Ⅳ 如何在shell腳本里使用sftp批量傳送文件
如何在shell腳本里使用sftp批量傳送文件
主要步驟如下:
1.為運行shell腳本的本地用戶生成密鑰對
2.將其中的公鑰分發到sftp欲登錄的遠程伺服器上
3.編寫並以上面的本地用戶運行shell腳本
一.生成密鑰對
在shell腳本中使用sftp時必須用到密鑰對(公鑰和私鑰).可使用下列方式生成(SSH 2.X版
本),這里本地用戶記為:local_user:
$ ssh-keygen –d
屏幕提示:
Generating public/private dsa key pair.
Enter file in which to save the key (/home/local_user/.ssh/id_dsa):
# 按回車保存為: /home/local_user/.ssh/id_dsa,即當前用戶local_user的私鑰
Enter passphrase (empty for no passphrase):
# 按回車,表示讀取密鑰時不需要密鑰的密碼
Enter same passphrase again:
# 確認密鑰的密碼,必須和上面的輸入相同
Your identification has been saved in /home/local_user/.ssh/id_dsa.
# 私鑰保存信息
Your public key has been saved in /home/local_user/.ssh/id_dsa.pub.
# 公鑰保存信息
The key fingerprint is:
ec:41:e8:08:38:0b:f8:1e:bc:92:98:32:fc:d7:69:7d ...
# 密鑰指紋
二.分發公鑰
為了使用密鑰,必須將公鑰分發到欲登錄的遠程伺服器上,這里遠程伺服器記為remote_hos
t,欲登錄的遠程用戶記為remote_user
1.公鑰到欲登錄的遠程伺服器的遠程用戶的家目錄下,例如:
id_dsa.pub到remote_host:/home/remote_user/.ssh/
若目錄/home/remote_user/.ssh/不存在,請先創建之.
2.將來的公鑰文件改名為authorized_keys
3.修改公鑰文件的訪問許可權
chmod 644 authorized_keys
三.示例
目標:
從遠程伺服器remote_host:/home/remote_user/data/
傳送下列文件到本地計算機的當前目錄: /home/local_user/data/:
20050201
20050202
20050203
20050204
20050205
方式1: 批模式
sftp提供了一個選項-b,用於集中存放sftp命令(該選項主要用於非交互模式的sftp).因此
對於上面的目標,可以生成如下的命令文件:
cd /home/remote_user/data/
lcd /home/local_user/data/
-get 20050201 .
-get 20050202 .
-get 20050203 .
-get 20050204 .
-get 20050205 .
quit
這里存為: sftp_cmds.txt
說明: get命令前加一個"-"以防止其執行錯誤時sftp執行過程被終止.
以下為腳本示例:
#!/bin/sh
sftp -b ./sftp_cmds.txt remote_user@remote_host
方式二:
#!/bin/sh
sftp remote_user@remote_host << EOF
cd /home/remote_user/data/
lcd /home/local_user/data/
-get 20050201 .
-get 20050202 .
-get 20050203 .
-get 20050204 .
-get 20050205 .
quit
EOF
Ⅳ 我在網上找的了一個shell腳本用於給FTP伺服器傳送文件,但是部分內容不懂 求大神賜教
FTPIT只是個標志,你看最後邊還有一個FTPIT,整體是這樣的
ftp -i -n $IP <<FTPIT
...
FTPIT
它就和<<EOF是一樣的,就是代表在前後兩個FTPIT之間的內容傳給ftp命令執行。
Ⅵ 如何編寫shell腳本通過ftp將一些文件自動上傳到另一台伺服器
建議使用rsync吧 ,直接可以同步,腳本話也沒啥,就一個定時任務
Ⅶ PowerShell上傳文件到FTP伺服器
$fileinf=New-Object System.Io.FileInfo("D:\My Documents\works\Downloads\2.txt")
$listFTP = [system.net.ftpwebrequest] [system.net.webrequest]::create`("ftp://115.*.*.*/"+$fileinf.name)
$listFTP.UseBinary = $true;
$listFTP.Credentials = New-Object System.Net.NetworkCredential("username","passwold")
$listFTP.Method=[system.net.WebRequestMethods+ftp]::UploadFile
$listFTP.KeepAlive=$false
$sourceStream = New-Object System.Io.StreamReader($fileInf.fullname)
$fileContents = [System.Text.Encoding]::UTF8.GetBytes($sourceStream.ReadToEnd())
$sourceStream.Close();
$listFTP.ContentLength = $fileContents.Length;
$requestStream = $listFTP.GetRequestStream();
$requestStream.Write($fileContents, 0, $fileContents.Length);
$requestStream.Close();
$response =$listFTP.GetResponse();
$response.StatusDescription
$response.Close();
以上是代碼,以下是返回。
226 Transfer complete. 7,146 bytes transferred. 3.79 KB/sec.
Ⅷ Linux shell 腳本ftp傳輸文件
ftp xxxxftp伺服器
put命令上傳
或者
輸入ftp
執行open xxxftp伺服器
然後 再執行
put命令上傳。
Ⅸ linux系統內 怎麼使用shell實現自動上傳文件到ftp伺服器
ftp自動登錄上傳單個文件。
把下面腳本另存為文件加入到crontab中即可實現ftp自動上傳文件。
####把本地/home/databachup/a.sh up ftp /home/databackup 下####
#!/bin/bash
ftp -n<<!
open 192.168.1.171
user guest 123456
binary
cd /home/data
lcd /home/databackup
prompt
put a.sh a.sh
close
bye
!
註解:
1. -n 不受.netrc文件的影響。(ftp默認為讀取.netrc文件中的設定)
2. << 是使用即時文件重定向輸入。
3. !是即時文件的標志它必須成對出現,以標識即時文件的開始和結尾。