GVKun编程网logo

<< END_SCRIPT通过bash连接到FTP时(shell连接ftp)

341

针对和shell连接ftp这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展./bash_script.sh后面传参数、centos–可以通过SSH连接–但不能通过SFTP连接?退出状态127

针对<< END_SCRIPT通过bash连接到FTP时shell连接ftp这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展./bash_script.sh后面传参数、centos – 可以通过SSH连接 – 但不能通过SFTP连接?退出状态127、delphi – 如何使用Indy连接到FTP时加密凭据?、Flash(ActionScript,AS) & JavaScript通信浅谈等相关知识,希望可以帮助到你。

本文目录一览:

<< END_SCRIPT通过bash连接到FTP时(shell连接ftp)

<< END_SCRIPT通过bash连接到FTP时(shell连接ftp)

我之前从未编写过 shell脚本,并试图理解这段代码:

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
exit 0

<<< END_SCRIPT表示什么?什么是报价电话呢?在此先感谢,再次,我是一个超级新手

解决方法

<<<在bash中是 heredoc syntax

对于quote,put,quit是FTP命令

./bash_script.sh后面传参数

./bash_script.sh后面传参数

直接在 ./bash_script.sh后面传参数 ,所有参数在$@,$1为第一个参数,$2第二个,for循环就可以获取了


centos – 可以通过SSH连接 – 但不能通过SFTP连接?退出状态127

centos – 可以通过SSH连接 – 但不能通过SFTP连接?退出状态127

不幸的是我无法通过sftp连接到我的VPS:

这是我的sshd_config:

# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports,IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 768

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin no
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile  %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_kNown_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/kNown_hosts for RhostsRSAAuthentication
#IgnoreUserKNownHosts yes

# To enable empty passwords,change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding no
X11displayOffset 10
PrintMotd yes
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no
UsednS yes

#MaxStartups 10:30:60
Banner no

# Allow setting environment variables
AcceptEnv LANG LC_*

#Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp /usr/lib/openssh/sftp-server
UsePAM yes

AllowUsers user@xx.xxx.xx.xxx user@xx.xxx.xx.xxx apt-dater@xx.xxx.xx.xxx

Match User user
    PasswordAuthentication yes

我的连接尝试的详细输出:

me:~ user$sftp -v user@example.org
OpenSSH_6.9p1,LibreSSL 2.1.8
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to example.org [xx.xxx.xx.xx] port 22.
debug1: Connection established.
debug1: identity file /Users/user/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/user/.ssh/id_rsa-cert type -1
debug1: identity file /Users/user/.ssh/id_dsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/user/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/user/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/user/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/user/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/user/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.9
debug1: Remote protocol version 2.0,remote software version OpenSSH_6.6.1
debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000
debug1: Authenticating to example.org:22 as 'user'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client chacha20-poly1305@openssh.com <implicit> none
debug1: kex: client->server chacha20-poly1305@openssh.com <implicit> none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:/RUeBQCA1w0nHUWT2OgLDhy7/bNQy4nWH2IVZatMLw4
debug1: Host 'example.org' is kNown and matches the RSA host key.
debug1: Found key in /Users/user/.ssh/kNown_hosts:4
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/user/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Authentication succeeded (publickey).
Authenticated to example.org ([xx.xxx.xx.xx]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = de_DE.UTF-8
debug1: Sending subsystem: sftp
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
debug1: channel 0: free: client-session,nchannels 1
debug1: fd 0 clearing O_NONBLOCK
Transferred: sent 3332,received 2796 bytes,in 0.2 seconds
Bytes per second: sent 18890.9,received 15852.0
debug1: Exit status 127
Connection closed

知道怎么解决这个问题吗?

它很可能意味着/usr/lib / openssh / sftp-server不存在.

确保Subsystem指令指向现有路径:

Subsystem sftp /usr/lib/openssh/sftp-server

或者实际上,现在你通常使用internal-sftp代替:

Subsystem sftp internal-sftp

见OpenSSH: Difference between internal-sftp and sftp-server.

delphi – 如何使用Indy连接到FTP时加密凭据?

delphi – 如何使用Indy连接到FTP时加密凭据?

最近我注意到在WireShark中我可以看到我用来连接我的FTP服务器上传文件的FTP用户名/密码(Delphi 6带有Indy 9或10,我相信).我想通过加密密码来防止这种情况,但我不知道从哪里开始.

你有什么建议阻止黑客获得凭据?请不要任何组件(甚至免费的)或任何花钱的东西.

解决方法

在纯FTP协议中,您无法加密任何内容,因此凭据以纯文本形式传输,文件,列表等以未加密的方式传送到服务器或从服务器传送.

如果您的服务器支持FTPS,这是通过SSL加密连接的普通FTP会话,您可以使用您正在使用的相同TIdFTP对象,但将默认IO处理程序更改为支持SSL的处理程序,例如,实例TIdSSLIOHandlerSocketopenSSL,使用流行的OpenSSL库进行加密.

在代码中它看起来像:

var
  ftp: TIdFTP;
  ssl: TIdSSLIOHandlerSocketopenSSL;
begin
  ftp := TIdFTP.Create();
  try
    ssl := TIdSSLIOHandlerSocketopenSSL.Create(ftp);
    ftp.IOHandler := ssl;
    ftp.Host := 'ftp.myserver.com';
    ftp.Username := 'myuser';
    ftp.Password := 'mypass';
    ftp.Connect;
    DoWhateverYouWantTodoWithThe(ftp);
    AndUploadMoreFiles(ftp);
    ftp.disconnect;
  finally
    ftp.Free;
  end;
end;

Flash(ActionScript,AS) & JavaScript通信浅谈

Flash(ActionScript,AS) & JavaScript通信浅谈

摘要:本文主要阐述两个问题:①如何进行Flash编程;②Flash(.swf)如何与JavaScript通信?这里牵涉到一门语言——ActionScript。关于它,百科上是这么说的,ActionScript(简称AS)是由Macromedia(现已被Adobe收购)为其Flash产品开发的 ,最初是一种简单的脚本语言,现在最新版本ActionScript3.0,是一种完全的面向对象的编程语言,功能强大,类库丰富,语法类似JavaScript,多用于Flash互动性、娱乐性、实用性开发,网页制作和RIA(丰富互联网程序)开发。


目录:

-------------------------------------------

- 工欲善其事必先利其器

- ActionScript与JavaScript函数绑定

    - ExternalInterface.addCallback(Js调用As)

    - ExternalInterface.call(As调用Js)


1.工欲善其事必先利其器

ActionScript或者说是Flash是使用什么编程工具呢?也可以直观的说.swf文件,是如何生成的?需要明白两点:①平时用户安装的“Adobe Flash Player for IE”,其实是一个播放网页Flash的插件。按道理来说Flash应该也是遵循NPAPI协议开发的(早期插件开发协议,先已经逐渐被PPAPI替代)。②Flash CSX系列开发工具,Flash Builder等等,这些很大,功能很强,可以进行全面的Flash动画开发。


但是,本文只牵涉到网络通信方面的,不涉及任何动画开发内容。推荐一款轻量级工具:FlashDevelop+Flex SDK,这是一款很好的swf开发工具。


环境配置十分之简单,①从网上搜索FlashDevelop下载、安装 ---> ②从AppMan中选择Flex SDK(OLD)安装(如下图)。整个过程个人感觉和AndroidStudio差不多,这里需要注意的是,默认路径是../AppData/Local/FlashDevelop/Apps,可以自行在菜单栏Tools中进行修改,一般直接使用即可,不要进行修改。


OK,让我们新建一个AS3.0项目,开始Flash开发之旅。



2.ActionScript与JavaScript函数绑定

Flash与JavaScript如何通信?这是本文的核心。涉及到一个绑定机制,先放个烟雾弹...  看完以下两个函数再继续拆除烟雾弹。

(注意,以下这两个方法都是写在.as中,非js)

//①

ExternalInterface.addCallback("send",send);

//②

ExternalInterface.call("onMessage",e.data);

你很聪明,可能根本不需要再看下文了,已经明白了其中的奥妙。


2.1 ExternalInterface.addCallback(Js调用As)

ExternalInterface.addCallback:有两个参数,第一个参数“send”——指定的是JavaScript函数名;第二个参数send——指定的是AS中的函数名(AS中必须有该函数的实现体,如下)。

///发送数据
public function send(sendMsg:String = null):void{
          if (g_tcp_xml_socket.connected){
                g_tcp_xml_socket.send(sendMsg);
          }
}

如此一来,在JavaScript中就可以来一波这样的操作了...

var swf = swfobject.getobjectById(''XXXFlash'');//swf的名称

///发送消息
function send(data){
try{
swf.send(data);
}
catch(exception){
alert(''send socket error.'');
}
}


回顾一下,也算是对上文的总结:首先JavaScript加载swf文件(获得swf对象);接着JavaScript通过swf对象,再调用send方法;而"send"方法在AS中已经被绑定到send方法上了,这样就会执行AS中的send方法。至此,一套完整的JavaScript调用ActionScript方法的流程就跑通了。


2.2 ExternalInterface.call(As调用Js)

来而不往非礼也,ActionScript如何调用JavaScript呢?也是一个绑定过程 ExternalInterface.call("onMessage",e.data); 这里的onMessage是一个JavaScript中的函数名,

///消息体
function onMessage(data){

}

仅一条语句,就实现了As调用Js方法。同时,也可以注意到,ExternalInterface.call 方式还完美的实现了,参数的传递。

文中尚未对swf到底如何加载进行阐明?后续的文章中将对其说明............


@qingdujun

2017-8-23 于湖南邵阳

今天关于<< END_SCRIPT通过bash连接到FTP时shell连接ftp的分享就到这里,希望大家有所收获,若想了解更多关于./bash_script.sh后面传参数、centos – 可以通过SSH连接 – 但不能通过SFTP连接?退出状态127、delphi – 如何使用Indy连接到FTP时加密凭据?、Flash(ActionScript,AS) & JavaScript通信浅谈等相关知识,可以在本站进行查询。

本文标签: