.Net FTPS Connection times out after sending 'CCC' command - ftp

I've been struggling a lot these last few days with a FTPS server that requires the 'CCC' command I'm trying to access via .Net
I'm using AlexFTPS Library. I'm able to connect and negociate AUTH TLS, I'm able to change directory but when I'm trying to list directory or download files, server asks for 'CCC' command. When I send 'CCC' command, I get a '200 CCC Context Enabled' reply but then I cannot send anything else, anytime I get a server timeout exception.
I've done further tests :
WS_FTP : works if I check the 'Use unencrypted command channel after SSL authentication' option
Filezilla : does not work even if I add 'CCC' as a Post Login Command
http://www.componentpro.com/ftp.net/ : works but is not open source
Any help would be so much appreciated... Sorry I am not FTP fluent...
Here's my code :
Using Client As New AlexPilotti.FTPS.Client.FTPSClient
AddHandler Client.LogCommand, Sub(sender As Object, args As AlexPilotti.FTPS.Common.LogCommandEventArgs)
Console.WriteLine(args.CommandText)
End Sub
AddHandler Client.LogServerReply, Sub(sender As Object, args As AlexPilotti.FTPS.Common.LogServerReplyEventArgs)
Console.WriteLine(args.ServerReply)
End Sub
Dim cred = New Net.NetworkCredential("login", "password")
Client.Connect("ftps.server.com", cred, AlexPilotti.FTPS.Client.ESSLSupportMode.CredentialsRequired)
Client.SendCustomCommand("SYST")
Client.SendCustomCommand("PBSZ 0")
Client.SendCustomCommand("PROT P")
Client.SendCustomCommand("FEAT")
Client.SendCustomCommand("PWD")
Client.SendCustomCommand("TYPE A")
Client.SendCustomCommand("PASV")
Client.SendCustomCommand("CCC")
Client.SendCustomCommand("LIST")
Console.ReadKey()
End Using
Thanks !

CCC ("Clear Command Channel") is a special command which downgrades the connection from SSL (started with AUTH TLS) back to unencrypted again. So it's no enough to just declare it as a custom command which gets send on the established control connection, it has to be handled similar to AUTH TLS by the FTPS library so that after the command is done the TLS downgrade occurs.

Related

Is it possible to work on normal (not SFTP) FTP on Renci SSH.NET? - which client to use?

I am using Renci SSH.NET, but trying to test on a FTP (not SFTP site).
I did get this working with WinSCP - but cannot get it to work on Renci -
WinSCP allows me to set the protocol to either FTP or SFTP - I think this is the issue - I am prompted for
No suitable authentication method found to complete authentication (publickey,keyboard-interactive).
How do I turn off SFTP (and just use FTP) on Renci SSH.NET? I tried
Dim c As Renci.SshNet.SftpClient / ScpClient/ BaseClient / NetConfClient
here is code:
Private Sub LancerUpload()
Dim PWAuthMeth = New PasswordAuthenticationMethod(Login, Password)
Dim KIAuthMeth = New KeyboardInteractiveAuthenticationMethod(Login)
AddHandler KIAuthMeth.AuthenticationPrompt, AddressOf HandleKeyEvent
Dim ConnectionInfo As New ConnectionInfo(ServerName, 22, Login, PWAuthMeth, KIAuthMeth)
Dim SshClient1 As New SshClient(ConnectionInfo)
Try
SshClient1.Connect()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
MsgBox(SshClient1.IsConnected)
End Sub
Private Sub HandleKeyEvent(sender As Object, e As Renci.SshNet.Common.AuthenticationPromptEventArgs)
For Each prompt As Renci.SshNet.Common.AuthenticationPrompt In e.Prompts
If prompt.Request.IndexOf("Password:", StringComparison.InvariantCultureIgnoreCase) <> -1 Then
prompt.Response = Password
End If
Next
End Sub
As the name says, the Renci SSH.NET library is an SSH library.
The FTP has nothing to do with the SSH nor the SFTP. Contrary to the SFTP, what in a subsystem of the SSH.
So no, you cannot use the Renci SSH.NET for the FTP protocol.
You may want to read Is "SFTP" and "FTP over SSL" a same thing? and Differences between SFTP and "FTP over SSH".

SMTP EOFError when Checking for Email Existence

I've written a simple script to test for the existence of an email address by initiating an SMTP communication without ever sending a message. For most domains, this works. But for some, like the one show below, I get an EOF error. I don't have this issue when using telnet to communicate with the SMTP server directly.
require 'net/smtp'
mx_server = 'mx1.optonline.net' # Example of a problematic mail host
Net::SMTP.start mx_server, 25 do |smtp|
smtp.helo 'mydomain.com'
smtp.mailfrom 'user#mydomain.com' # Triggers an EOF error
smtp.rcptto 'target#optonline.net' # Typically triggers an error if the address doesn't exist
end

TCP Minecraft Server in Ruby

I'm attempting to create a script in ruby that connects to a Minecraft server via TCP and fetches the current number of players much like the PHP script at http://www.webmaster-source.com/2012/07/05/checking-the-status-of-a-minecraft-server-with-php/
When running the code below I get �Took too long to log in
require 'socket'
server = TCPSocket.new '192.241.174.210', 25565
while line = server.gets
puts line
end
server.close
What am I doing wrong here?
you're not sending this:
fwrite($sock, "\xfe");
from the script you linked. You have to send that before you call read, like they do.
Basically the server is waiting for you to send data and when you don't after a timeout, you are disconnected.

Sending an email from R using the sendmailR package

I am trying to send an email from R, using the sendmailR package. The code below works fine when I run it on my PC, and I recieve the email. However, when I run it with my macbook pro, it fails with the following error:
library(sendmailR)
from <- sprintf("<sendmailR#%s>", Sys.info()[4])
to <- "<myemail#gmail.com>"
subject <- "TEST"
sendmail(from, to, subject, body,
control=list(smtpServer="ASPMX.L.GOOGLE.COM"))
Error in socketConnection(host = server, port = port, blocking = TRUE) :
cannot open the connection
In addition: Warning message:
In socketConnection(host = server, port = port, blocking = TRUE) :
ASPMX.L.GOOGLE.COM:25 cannot be opened
Any ideas as to why this would work on a PC, but not a mac? I turned the firewall off on both machines.
Are you able to send email via the command-line?
So, first of all, fire up a Terminal and then
$ echo “Test 123” | mail -s “Test” user#domain.com
Look into /var/log/mail.log, or better use
$ tail -f /var/log/mail.log
in a different window while you send your email. If you see something like
... setting up TLS connection to smtp.gmail.com[xxx.xx.xxx.xxx]:587
... Trusted TLS connection established to smtp.gmail.com[xxx.xx.xxx.xxx]:587:\
TLSv1 with cipher RC4-MD5 (128/128 bits)
then you succeeded. Otherwise, it means you have to configure you mailing system. I use postfix with Gmail for two years now, and I never had have problem with it. Basically, you need to grab the Equifax certificates, Equifax_Secure_CA.pem from here: http://www.geotrust.com/resources/root-certificates/. (They were using Thawtee certificates before but they changed last year.) Then, assuming you used Gmail,
Create relay_password in /etc/postfix and put a single line like this (with your correct login and password):
smtp.gmail.com login#gmail.com:password
then in a Terminal,
$ sudo postmap /etc/postfix/relay_password
to update Postfix lookup table.
Add the certificates in /etc/postfix/certs, or any folder you like, then
$ sudo c_rehash /etc/postfix/certs/
(i.e., rehash the certificates with Openssl).
Edit /etc/postfix/main.cf so that it includes the following lines (adjust the paths if needed):
relayhost = smtp.gmail.com:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/relay_password
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = may
smtp_tls_CApath = /etc/postfix/certs
smtp_tls_session_cache_database = btree:/etc/postfix/smtp_scache
smtp_tls_session_cache_timeout = 3600s
smtp_tls_loglevel = 1
tls_random_source = dev:/dev/urandom
Finally, just reload the Postfix process, with e.g.
$ sudo postfix reload
(a combination of start/stop works too).
You can choose a different port for the SMTP, e.g. 465.
It’s still possible to use SASL without TLS (the above steps are basically the same), but in both case the main problem is that your login informations are available in a plan text file... Also, should you want to use your MobileMe account, just replace the Gmail SMTP server with smtp.me.com.

Send mail from a Windows script

I would like to send mail from a script on a Windows Server 2003 Standard Edition. I think the server setup is pretty much out of the box.
The mail server is an Exchange one, and when you're on the internal network you can use plain old SMTP. I have done it from my machine with Perl, but unfortunately Perl is not available on the server.
Is there an easy way of doing this from a .bat-file or any other way that doesn't require installing some additional software?
Edit:
Thanks for the quick replies. The "blat" thingie would probably work fine but with wscript I don't have to use a separate binary.
I didn't see PhiLho's post the first time I edited and selected an answer. No need for me to duplicate the code here.
Just save the script to a file, say sendmail.vbs, and then call it from the command prompt like so:
wscript sendmail.vbs
It is possible with Wscript, using CDO:
Dim objMail
Set objMail = CreateObject("CDO.Message")
objMail.From = "Me <Me#Server.com>"
objMail.To = "You <You#AnotherServer.com>"
objMail.Subject = "That's a mail"
objMail.Textbody = "Hello World"
objMail.AddAttachment "C:\someFile.ext"
---8<----- You don't need this part if you have an active Outlook [Express] account -----
' Use an SMTP server
objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
' Name or IP of Remote SMTP Server
objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"smtp.server.com"
' Server port (typically 25)
objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMail.Configuration.Fields.Update
----- End of SMTP usage ----->8---
objMail.Send
Set objMail=Nothing
Wscript.Quit
Update: found more info there: VBScript To Send Email Using CDO
By default it seems it uses Outlook [Express], so it didn't worked on my computer but you can use a given SMTP server, which worked fine for me.
If the server happened (I realize how old this question is) to have Powershell v2 installed, the CmdLet Send-MailMessage would do this in one line.
Send-MailMessage [-To] <string[]> [-Subject] <string> -From <string> [[-Body] <string>] [[-SmtpServer] <string>] [-Attachments <string[]>] [-Bcc <string[]>] [-BodyAsHtml] [-Cc <string[]>] [-Credential <PSCredential>] [-DeliveryNotficationOption {None | OnSuccess | OnFailure | Delay | Never}] [-Encoding <Encoding>] [-Priority {Normal | Low | High}] [-UseSsl] [<CommonParameters>]
I don't know if dropping a binary alongside the .bat file counts as installing software, but, if not, you can use blat to do this.
If you have outlook/exchange installed you should be able to use CDONTs, just create a mail.vbs file and call it in a batch file like so (amusing they are in the same dir)
wscript mail.vbs
for the VBScript code check out
http://support.microsoft.com/kb/197920
http://www.w3schools.com/asp/asp_send_email.asp
forget the fact they the two links speak about ASP, it should work fine as a stand alone script with out iis.
I think that you'll have to install some ActiveX or other component what could be invoked from WScript, such as:
http://www.activexperts.com/ActivEmail/
and:
http://www.emailarchitect.net/webapp/SMTPCOM/developers/scripting.asp
Otherwise, you'll have to write the entire SMTP logic (if possible, not sure) in WScript all on your own.
Use CDONTS with Windows Scripting Host (WScript)
Is there a way you send without referencing the outside schema urls.
http://schemas.microsoft.com/cdo/configuration/
That is highly useless as it can't be assumed all boxes will have outside internet access to send mail internally on the local exchange. Is there a way to save the info from those urls locally?

Resources