dongzhuo5425 2016-01-14 10:21
浏览 73
已采纳

无法请求伪终端

I am trying to connect to SFTP server. Here is the code :

  set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
  require_once('Crypt/RSA.php');
  require_once('Net/SSH2.php');
  require_once('Net/SFTP.php');
  $ssh = new Net_SFTP('some.server.com', '22000');
  if (!$ssh->login('my_login', 'my_password')) {
     $log->lwrite('SSh Login Failed');
  }
  $dir = "output/";
  $files = glob($dir . "*.*");

  foreach($files as $file)
  {
    $fileName = substr($file,strrpos($file,"/")+1);
    if (substr($file,-4) == ".asc"){
        $output = $ssh->put('dir/'.$fileName,$file,FTP_ASCII); // FTP_BINARY
    }
  }

I'm 100 percent sure, that the host, password and login is correct. Because I can access the server with this input through WinSCP. However this is the response I get:

Notice: Unable to request pseudo-terminal in ***/Net/SSH2.php on line 2195

Notice: Connection closed prematurely in ***/Net/SSH2.php on line 2303

This is the first time I ever encountered a notice like this. I've already tried to find the answer here, but I found nothing so I had to ask.

Btw every 2-30 seconds sftp server disconnects me when I'm connected through WinSCP with error :

Network error: Software caused connection abort

I can say from log, that I get

NET_SSH2_MSG_USERAUTH_SUCCESS

also

NET_SSH2_MSG_CHANNEL_OPEN_CONFIRMATION and NET_SSH2_MSG_CHANNEL_EXTENDED_DATA

after which it says Welcome message (local time, experimental ftp server and so on). But after that I get:

NET_SSH2_MSG_DISCONNECT

So please, can anybody tell me why does this happen? Thank you in advance :-)

P.S: I have no control of the sftp server that I'm trying to connect to.


EDIT:

This is the line that is causing the problem :

!$ssh->login('my_login', 'my_password')

And as i said: login, host, port and password are 100% correct.

EDIT2: extracted log

00000000  SSH-2.0-mod_sftp
00000010  /0.9.9..

->
00000000  SSH-2.0-phpsecli
00000010  b_1.0 (openssl, 
00000020  bcmath)..

<- NET_SSH2_MSG_KEXINIT (since last: 0.1568, network: 0.0003s)
00000000  p.p ._!...I.$p}.
00000010  ....ecdh-sha2-ni
00000020  stp256,ecdh-sha2
00000030  -nistp384,ecdh-s
00000040  ha2-nistp521,dif
00000050  fie-hellman-grou
00000060  p-exchange-sha25
00000070  6,diffie-hellman
00000080  -group-exchange-
00000090  sha1,diffie-hell
000000a0  man-group14-sha1
000000b0  ,diffie-hellman-
000000c0  group1-sha1,rsa1
000000d0  024-sha1....ssh-
000000e0  rsa,ssh-dss....a
000000f0  es256-ctr,aes192
00000100  -ctr,aes128-ctr,
00000110  aes256-cbc,aes19
00000120  2-cbc,aes128-cbc
00000130  ,blowfish-ctr,bl
00000140  owfish-cbc,cast1
00000150  28-cbc,arcfour25
00000160  6,arcfour128,3de
00000170  s-ctr,3des-cbc..
00000180  ..aes256-ctr,aes
00000190  192-ctr,aes128-c
000001a0  tr,aes256-cbc,ae
000001b0  s192-cbc,aes128-
000001c0  cbc,blowfish-ctr
000001d0  ,blowfish-cbc,ca
000001e0  st128-cbc,arcfou
000001f0  r256,arcfour128,
00000200  3des-ctr,3des-cb
00000210  c...jhmac-sha2-2
00000220  56,hmac-sha2-512
00000230  ,hmac-sha1,hmac-
00000240  sha1-96,hmac-md5
00000250  ,hmac-md5-96,hma
00000260  c-ripemd160,umac
00000270  -64@openssh.com.
00000280  ..jhmac-sha2-256
00000290  ,hmac-sha2-512,h
000002a0  mac-sha1,hmac-sh
000002b0  a1-96,hmac-md5,h
000002c0  mac-md5-96,hmac-
000002d0  ripemd160,umac-6
000002e0  4@openssh.com...
000002f0  .none....none...
00000300  ..........

-> NET_SSH2_MSG_KEXINIT (since last: 0.0148, network: 0s)
00000000  .......]H.0fFwBZ
00000010  ...~diffie-hellm
00000020  an-group1-sha1,d
00000030  iffie-hellman-gr
00000040  oup14-sha1,diffi
00000050  e-hellman-group-
00000060  exchange-sha1,di
00000070  ffie-hellman-gro
00000080  up-exchange-sha2
00000090  56....ssh-rsa,ss
000000a0  h-dss....arcfour
000000b0  256,arcfour128,a
000000c0  es128-ctr,aes192
000000d0  -ctr,aes256-ctr,
000000e0  twofish128-ctr,t
000000f0  wofish192-ctr,tw
00000100  ofish256-ctr,aes
00000110  128-cbc,aes192-c
00000120  bc,aes256-cbc,tw
00000130  ofish128-cbc,two
00000140  fish192-cbc,twof
00000150  ish256-cbc,twofi
00000160  sh-cbc,blowfish-
00000170  ctr,blowfish-cbc
00000180  ,3des-ctr,3des-c
00000190  bc....arcfour256
000001a0  ,arcfour128,aes1
000001b0  28-ctr,aes192-ct
000001c0  r,aes256-ctr,two
000001d0  fish128-ctr,twof
000001e0  ish192-ctr,twofi
000001f0  sh256-ctr,aes128
00000200  -cbc,aes192-cbc,
00000210  aes256-cbc,twofi
00000220  sh128-cbc,twofis
00000230  h192-cbc,twofish
00000240  256-cbc,twofish-
00000250  cbc,blowfish-ctr
00000260  ,blowfish-cbc,3d
00000270  es-ctr,3des-cbc.
00000280  ..9hmac-sha2-256
00000290  ,hmac-sha1-96,hm
000002a0  ac-sha1,hmac-md5
000002b0  -96,hmac-md5...9
000002c0  hmac-sha2-256,hm
000002d0  ac-sha1-96,hmac-
000002e0  sha1,hmac-md5-96
000002f0  ,hmac-md5....non
00000300  e....none.......
00000310  ......

-> NET_SSH2_MSG_KEXDH_INIT (since last: 0.0936, network: 0.0001s)
some data (not sure if safe to share)

<- NET_SSH2_MSG_KEXDH_REPLY (since last: 0.0228, network: 0.0228s)
some data (not sure if safe to share)

-> NET_SSH2_MSG_NEWKEYS (since last: 0.0169, network: 0.0002s)


<- NET_SSH2_MSG_NEWKEYS (since last: 0.0001, network: 0s)


-> NET_SSH2_MSG_SERVICE_REQUEST (since last: 0.0332, network: 0s)
00000000  ....ssh-userauth

<- NET_SSH2_MSG_SERVICE_ACCEPT (since last: 0.026, network: 0.0259s)
00000000  ....ssh-userauth

-> NET_SSH2_MSG_USERAUTH_REQUEST (since last: 0.0004, network: 0.0002s)
00000000  ....username....
00000010  ssh-connection..
00000020  ..password.....p
00000030  assword

<- NET_SSH2_MSG_USERAUTH_SUCCESS (since last: 0.1056, network: 0.1052s)


-> NET_SSH2_MSG_CHANNEL_OPEN (since last: 0.0003, network: 0.0001s)
00000000  ....session.....
00000010  .....@.

<- NET_SSH2_MSG_CHANNEL_OPEN_CONFIRMATION (since last: 0.0114, network: 0.0001s)
00000000  ................

-> NET_SSH2_MSG_CHANNEL_REQUEST (since last: 0.0003, network: 0.0001s)
00000000  ........subsyste
00000010  m.....sftp

<- NET_SSH2_MSG_CHANNEL_EXTENDED_DATA (since last: 0.018, network: 0.0005s)
00000000  ............Welc
00000010  ome, archive use
00000020  r some-server@
00000030  somevps.nameserve
00000040  r.sk !....The lo
00000050  cal time is: Thu
00000060  Jan 21 09:25:45
00000070  2016....This is
00000080  an experimental
00000090  FTP server.  If
000000a0  you have any un
000000b0  usual problems,.
000000c0  .please report t
000000d0  hem via e-mail t
000000e0  o .someemail.sk
000000f0  >.....

-> NET_SSH2_MSG_DISCONNECT (since last: 0.0006, network: 0.0004s)
00000000  ............
  • 写回答

3条回答 默认 最新

  • dongnianwo8289 2016-02-10 13:50
    关注

    Since i wasnt able to make this script work (still dont understant why it suddenly stopped working) i changed the code so it use ssh2 pecl extension and it suddenly started to work. Here is the script, that is actually working:

      $connection = ssh2_connect('ftp.server.com', port);
      ssh2_auth_password($connection, 'login', 'password');
      $sftp = ssh2_sftp($connection);
    
      $dir = "/";
      $files = glob($dir . "*.*");
    
      foreach($files as $file){
        $fileName = substr($file,strrpos($file,"/")+1);
        if (substr($file,-4) == ".asc"){
            ssh2_scp_send($connection, $file, 'dir/'.$fileName); 
        }
      }
    

    I would still like to know what happened or what might cause that error. I hope that the script above will help anybody who encoutered the same error as I did.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R