public void STOR_DELEマンド_V6() { var cl = _v6Cl; //共通処理(ログイン成功) Login("user1", cl); //port var port = 249; cl.StringSend("PORT 127,0,0,1,0,249"); var dl = SockServer.CreateConnection(new Kernel(), new Ip(IpKind.V4Localhost), port, null, this); Assert.That(cl.StringRecv(1, this), Is.EqualTo("200 PORT command successful.\r\n")); //stor cl.StringSend("STOR 0.txt"); Assert.That(cl.StringRecv(1, this), Is.EqualTo("150 Opening ASCII mode data connection for 0.txt.\r\n")); dl.Send(new byte[3]); dl.Close(); Assert.That(cl.StringRecv(1, this), Is.EqualTo("226 Transfer complete.\r\n")); //dele cl.StringSend("DELE 0.txt"); Assert.That(cl.StringRecv(1, this), Is.EqualTo("250 Dele command successful.\r\n")); }
public void LISTコマンド_V6() { var cl = _v6Cl; //共通処理(ログイン成功) Login("user1", cl); //port var port = 251; cl.StringSend("PORT 127,0,0,1,0,251"); var dl = SockServer.CreateConnection(new Kernel(), new Ip(IpKind.V4Localhost), port, null, this); Assert.That(cl.StringRecv(1, this), Is.EqualTo("200 PORT command successful.\r\n")); //list cl.StringSend("LIST -la"); Assert.That(cl.StringRecv(1, this), Is.EqualTo("150 Opening ASCII mode data connection for ls.\r\n")); Assert.That(listMask(dl.StringRecv(3, this)), Is.EqualTo("drwxrwxrwx 1 nobody nogroup nnnn mon dd hh:mm home0\r\n")); Assert.That(listMask(dl.StringRecv(3, this)), Is.EqualTo("drwxrwxrwx 1 nobody nogroup nnnn mon dd hh:mm home1\r\n")); Assert.That(listMask(dl.StringRecv(3, this)), Is.EqualTo("drwxrwxrwx 1 nobody nogroup nnnn mon dd hh:mm home2\r\n")); Assert.That(listMask(dl.StringRecv(3, this)), Is.EqualTo("-rwxrwxrwx 1 nobody nogroup nnnn mon dd hh:mm 1.txt\r\n")); Assert.That(listMask(dl.StringRecv(3, this)), Is.EqualTo("-rwxrwxrwx 1 nobody nogroup nnnn mon dd hh:mm 2.txt\r\n")); Assert.That(listMask(dl.StringRecv(3, this)), Is.EqualTo("-rwxrwxrwx 1 nobody nogroup nnnn mon dd hh:mm 3.txt\r\n")); dl.Close(); }
void Pipe() { _sockTcp = SockServer.CreateConnection(_kernel, _ip, _listenPort, null, this); if (_sockTcp != null) { while (_life) { var len = _sockTcp.Length(); if (len > 0) { const int tout = 3; //受信バイト数がわかっているので、ここでのタイムアウト値はあまり意味が無い var b = _sockTcp.Recv(len, tout, this); if (b != null) { _buffer = Bytes.Create(_buffer, b); } } if (_sockTcp.Length() == 0 && _sockTcp.SockState != SockState.Connect) { break; } } _sockTcp.Close(); } IsRecv = false; }
private bool JobPasv(Session session, FtpCmd ftpCmd) { var port = session.Port; var ip = session.SockCtrl.LocalIp; // �f�[�^�X�g���[���̃\�P�b�g�̍쐬 for (int i = 0; i < 100; i++) { port++; if (port >= 9999) { port = 2000; } //�o�C���h�\���ǂ����̊m�F if (SockServer.IsAvailable(Kernel, ip, port)) { //���� if (ftpCmd == FtpCmd.Epsv) { //Java fix Ver5.8.3 //session.StringSend(string.Format("229 Entering Extended Passive Mode. (|||{0}|)", port)); session.StringSend(string.Format("229 Entering Extended Passive Mode (|||{0}|)", port)); } else { var ipStr = ip.ToString(); //Java fix Ver5.8.3 //session.StringSend(string.Format("227 Entering Passive Mode. ({0},{1},{2})", ipStr.Replace('.',','), port/256, port%256)); session.StringSend(string.Format("227 Entering Passive Mode ({0},{1},{2})", ipStr.Replace('.', ','), port / 256, port % 256)); } //�w�肵���A�h���X�E�|�[�g�ő҂��� var sockData = SockServer.CreateConnection(Kernel, ip, port, null, this); if (sockData == null) { //�ڑ����s return(false); } if (sockData.SockState != Bjd.sock.SockState.Error) { //�Z�b�V�������̕ۑ� session.Port = port; session.SockData = sockData; return(true); } } } session.StringSend("500 command not understood:"); return(true); }
private bool JobPasv(Session session, FtpCmd ftpCmd) { var port = session.Port; var ip = session.SockCtrl.LocalIp; // データストリームのソケットの作成 for (int i = 0; i < 100; i++) { port++; if (port >= 9999) { port = 2000; } //バインド可能かどうかの確認 if (SockServer.IsAvailable(Kernel, ip, port)) { //成功 if (ftpCmd == FtpCmd.Epsv) { //Java fix Ver5.8.3 //session.StringSend(string.Format("229 Entering Extended Passive Mode. (|||{0}|)", port)); session.StringSend(string.Format("229 Entering Extended Passive Mode (|||{0}|)", port)); } else { var ipStr = ip.ToString(); //Java fix Ver5.8.3 //session.StringSend(string.Format("227 Entering Passive Mode. ({0},{1},{2})", ipStr.Replace('.',','), port/256, port%256)); session.StringSend(string.Format("227 Entering Passive Mode ({0},{1},{2})", ipStr.Replace('.', ','), port / 256, port % 256)); } //指定したアドレス・ポートで待ち受ける var sockData = SockServer.CreateConnection(Kernel, ip, port, null, this); if (sockData == null) { //接続失敗 return(false); } if (sockData.SockState != Bjd.sock.SockState.Error) { //セッション情報の保存 session.Port = port; session.SockData = sockData; return(true); } } } session.StringSend("500 command not understood:"); return(true); }
public void EPRTコマンド() { var cl = _v6Cl; //共通処理(ログイン成功) Login("user1", cl); var port = 252; //テストの連続のためにPORTコマンドのテストとはポート番号をずらす必要がある cl.StringSend("EPRT |2|::1|252|"); var dl = SockServer.CreateConnection(new Kernel(), new Ip(IpKind.V6Localhost), port, null, this); Assert.That(cl.StringRecv(1, this), Is.EqualTo("200 EPRT command successful.\r\n")); dl.Close(); }
public void PORTコマンド() { var cl = _v4Cl; //共通処理(ログイン成功) Login("user1", cl); int port = 256; //テストの連続のためにPORTコマンドのテストとはポート番号をずらす必要がある cl.StringSend("PORT 127,0,0,1,0,256"); SockTcp dl = SockServer.CreateConnection(new Kernel(), new Ip(IpKind.V4Localhost), port, null, this); Assert.That(cl.StringRecv(1, this), Is.EqualTo("200 PORT command successful.\r\n")); dl.Close(); }
protected override void OnRunThread() { ThreadBaseKind = ThreadBaseKind.Running; int timeout = 3; _sock[CS.Client] = new SockTcp(_kernel, _connectIp, _connectPort, timeout, null); _sock[CS.Server] = SockServer.CreateConnection(_kernel, _listenIp, _listenPort, null, this); while (IsLife()) { for (var i = 0; i < 2; i++) { var cs = (i == 0) ? CS.Server : CS.Client; if (_buf[cs].Length == 0) { var len = _sock[cs].Length(); if (len != 0) { _tunnel.ResetIdle();//アイドル時間の更新 _buf[cs] = _sock[cs].Recv(len, 1, this); } } if (_buf[cs].Length != 0) { var s = _sock[((i == 0) ? CS.Client : CS.Server)].Send(_buf[cs]); if (-1 != s) { _buf[cs] = new byte[0]; } } } if (_sock[CS.Server].SockState != SockState.Connect && _sock[CS.Server].Length() == 0) { break; } if (_sock[CS.Client].SockState != SockState.Connect && _sock[CS.Client].Length() == 0) { break; } } _sock[CS.Client].Close(); _sock[CS.Server].Close(); }
public void DOWNユーザはSTORに失敗する_V6() { var cl = _v6Cl; //共通処理(ログイン成功) Login("user3", cl); //port var port = 249; cl.StringSend("PORT 127,0,0,1,0,249"); var dl = SockServer.CreateConnection(new Kernel(), new Ip(IpKind.V4Localhost), port, null, this); Assert.That(cl.StringRecv(1, this), Is.EqualTo("200 PORT command successful.\r\n")); //stor cl.StringSend("STOR 0.txt"); Assert.That(cl.StringRecv(1, this), Is.EqualTo("550 Permission denied.\r\n")); }
public void UPユーザはRETRに失敗する_V6() { var cl = _v6Cl; //共通処理(ログイン成功) Login("user2", cl); //port var port = 250; cl.StringSend("PORT 127,0,0,1,0,250"); var dl = SockServer.CreateConnection(new Kernel(), new Ip(IpKind.V4Localhost), port, null, this); Assert.That(cl.StringRecv(1, this), Is.EqualTo("200 PORT command successful.\r\n")); //retr cl.StringSend("RETR 3.txt"); Assert.That(cl.StringRecv(1, this), Is.EqualTo("550 Permission denied.\r\n")); // Thread.Sleep(10); // Assert.That(dl.Length, Is.EqualTo(24)); dl.Close(); }
public void RETRコマンド_V6() { var cl = _v6Cl; //共通処理(ログイン成功) Login("user1", cl); //port var port = 250; cl.StringSend("PORT 127,0,0,1,0,250"); var dl = SockServer.CreateConnection(new Kernel(), new Ip(IpKind.V4Localhost), port, null, this); Assert.That(cl.StringRecv(1, this), Is.EqualTo("200 PORT command successful.\r\n")); //retr cl.StringSend("RETR 3.txt"); Assert.That(cl.StringRecv(1, this), Is.EqualTo("150 Opening ASCII mode data connection for 3.txt (24 bytes).\r\n")); Thread.Sleep(10); Assert.That(dl.Length(), Is.EqualTo(24)); dl.Close(); }
//サーバ側若しくはクライアント側どちらかのSockTcpは、Listen状態で生成が終わっている //そして、その接続の待ち受け開始は、このクラスの中で行われる //接続が完了した後、反対側のサーバ(Ip,port)へ、コネクトする public DataThread(Kernel kernel, Logger logger, int clientPort, int serverPort, Ip bindAddr, Ip ip, int port, int timeout) { _kernel = kernel; _logger = logger; _timeout = timeout; _ip = ip; _port = port; _sock[CS.Client] = null; _sock[CS.Server] = null; if (serverPort != 0) //サーバ側がListen状態の場合 PASV { _sock[CS.Server] = SockServer.CreateConnection(kernel, bindAddr, serverPort, null, this); if (_sock[CS.Server] == null) { return; } } else if (clientPort != 0) //クライアント側がListen状態の場合 PORT { _sock[CS.Client] = SockServer.CreateConnection(kernel, bindAddr, clientPort, null, this); if (_sock[CS.Client] == null) { return; } } //パイプスレッドの生成 _t = new Thread(Pipe) { IsBackground = true }; _t.Start(); }