網頁

顯示具有 sftp 標籤的文章。 顯示所有文章
顯示具有 sftp 標籤的文章。 顯示所有文章

2023年3月9日 星期四

lftp in wsl

vi ~/.ssh/config
Host 192.168.5.9
        KexAlgorithms +diffie-hellman-group1-sha1
        HostKeyAlgorithms ssh-rsa
        PubkeyAcceptedKeyTypes ssh-rsa

lftp command

set FTP_USER=digichance
set FTP_PASSWD=sh22463458
set FTP_SITE=114.33.245.149
set FTP_PORT=22
rem set FTP_PORT=7010
set FTP_LOCAL=/cygdrive/D/Photo
set FTP_REMOTE=/d:/temp
set FTP_CMD=lftp.exe
set PATH=%PATH%;C:\lftp-4.9.2.win64-openssl\bin
set PUT=Y
set REMOVE_SOURCE=N

set today=%date:~0,10%
set dy=%today:~0,4%
set dm=%today:~5,2%
set dd=%today:~8,2%
set YES_DAY=%dy%%dm%%dd%
call YesDay.bat %YES_DAY%
echo %YES_DAY%
call YesDay.bat %YES_DAY%
echo %YES_DAY%

if "%REMOVE_SOURCE%"=="Y" (
    set REMOVE_CMD=--Remove-source-dirs
) else (
    set REMOVE_CMD=
)
if "%PUT%"=="Y" (
    set FILE_LIST=-R %FTP_LOCAL%/%1 %1
) else (
    set FILE_LIST=%1 %FTP_LOCAL%/%1
)
%FTP_CMD% -c "set sftp:auto-confirm yes;set net:timeout 5;set net:max-retries 3; open -u %FTP_USER%,%FTP_PASSWD% -p %FTP_PORT% sftp://%FTP_SITE%; cd %FTP_REMOTE%; mirror %REMOVE_CMD% %FILE_LIST%; quit"

rem GET YESTERDAY DATE
rem for Windows 2000,XP,2003
rem http://hi.baidu.com/uroot
@echo off

set dt=%1%
rem date format is "YYYYMMDD"

rem set /P dt="Input Date: "

set dy=%dt:~0,4%
set dm=%dt:~4,2%
set dd=%dt:~6,2%

echo %dy%-%dm%-%dd%
if %dm%%dd%==0101 goto L01
if %dm%%dd%==0201 goto L02
if %dm%%dd%==0301 goto L07
if %dm%%dd%==0401 goto L02
if %dm%%dd%==0501 goto L04
if %dm%%dd%==0601 goto L02
if %dm%%dd%==0701 goto L04
if %dm%%dd%==0801 goto L02
if %dm%%dd%==0901 goto L02
if %dm%%dd%==1001 goto L05
if %dm%%dd%==1101 goto L03
if %dm%%dd%==1201 goto L06

if %dd%==02 goto L10
if %dd%==03 goto L10
if %dd%==04 goto L10
if %dd%==05 goto L10
if %dd%==06 goto L10
if %dd%==07 goto L10
if %dd%==08 goto L10
if %dd%==09 goto L10
if %dd%==10 goto L11
set /A dd=dd-1
set dt=%dy%-%dm%-%dd%
goto END
:L10
set /A dd=%dd:~1,1%-1
set dt=%dy%-%dm%-0%dd%
set dd=0%dd%
goto END
:L11
set dt=%dy%-%dm%-09
set dd=09  
goto END

:L02
set /A dm=%dm:~1,1%-1
set dt=%dy%-0%dm%-31
set dm=0%dm%
set dd=31
goto END
:L04
set /A dm=dm-1
set dt=%dy%-0%dm%-30
set dm=0%dm%
set dd=30
goto END

:L05
set dt=%dy%-09-30
set dm=09
set dd=30
goto END
:L03
set dt=%dy%-10-31
set dm=10
set dd=31
goto END
:L06
set dt=%dy%-11-30
set dm=11
set dd=30
goto END
:L01
set /A dy=dy-1
set dt=%dy%-12-31
set dm=12
set dd=31
goto END

:L07
set /A "dd=dy%%4"
if not %dd%==0 goto L08
set /A "dd=dy%%100"
if not %dd%==0 goto L09
set /A "dd=dy%%400"
if %dd%==0 goto L09
:L08
set dt=%dy%-02-28
set dm=02
set dd=28
goto END
:L09
set dt=%dy%-02-29
set dm=02
set dd=29
goto END

:END
rem echo %dt%
set YES_DAY=%dy%%dm%%dd%

2020年4月27日 星期一

sftp lftp

伺服器端可以安裝簡易版的 Rebex Tiny SFTP Server


客戶端
若是 win7 需要
安裝 Microsoft .NET Framework 4
安裝 Microsoft .NET Framework 4.5
安裝 PowerShell 3.0
使用 administrator 開啟 powershell
install Chocolatey 它就像是 windows 版的 apt-get
再安裝 lftp
PS C;\> Get-ExecutionPolicy
PS C;\> Set-ExecutionPolicy AllSigned
PS C;\> Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
PS C;\> choco install lftp


man lftp

download
lftp -c "set sftp:auto-confirm yes; open -u username,passowrd -p port sftp://ip; mirror -e -p remote_path local_path; quit"

upload
lftp -c "set sftp:auto-confirm yes; open -u username,passowrd -p port sftp://ip; mirror -e -p -R local_path remote_path; quit"

mkdir
lftp -c "set sftp:auto-confirm yes; open -u username,password -p port sftp://ip; mkdir -p /pathA/pathB; quit"

cd, lcd, mput
lftp -c "set sftp:auto-confirm yes; open -u username,password -p port sftp://ip; lcd /localPath; cd /remotePath; mput *; quit"

mirror with Regular Expression
lftp -c "set sftp:auto-confirm yes; open -u username,password -p port sftp://ip; mirror -x 'jpg$' -R /localPath /remotePath; quit"
lftp -c "set sftp:auto-confirm yes; open -u username,password -p port sftp://ip; mirror -i 'ini$|sign$' -R /localPath /remotePath; quit"


windows path to unix path
d:\path
/cygdrive/d/path