Connect to FTP server through same network - python

I'm hosting my FTP through XAMPP, and I'm trying to access the FTP from my other PC, but I cant seem to connect. I wrote a python script, which works on the PC hosting the FTP, but not on my other PC.
# Import Module
import ftplib
# Fill Required Information
HOSTNAME = "10.224.18.9"
USERNAME = "z2067"
PASSWORD = "password"
# Connect FTP Server
ftp_server = ftplib.FTP(HOSTNAME, USERNAME, PASSWORD)
# force UTF-8 encoding
ftp_server.encoding = "utf-8"
# Get list of files
ftp_server.dir()
OUTPUT:
drwxr-xr-x 1 ftp ftp 0 Jan 07 2022 36890
drwxr-xr-x 1 ftp ftp 0 Jan 06 2022 37064
drwxr-xr-x 1 ftp ftp 0 Jan 06 2022 37072
-rw-r--r-- 1 ftp ftp 116 Jan 18 2022 desktop.ini
When I run it on my other PC i get the following error:
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
I was wondering what settings I have to change on my FTP server hosted by XAMPP, to be able to access this FTP from my other PC?
I have some settings pics here:

It looks like you are using the public IP address for the server. If both devices are in the same network I suggest trying the IP address visible inside that network instead.
If you follow this tutorial: https://lazyadmin.nl/it/ipconfig-command/ you can find out what that IP address is for the computer you are running XAMPP on. It should look something like 192.168.x.x. Try using that in your python code instead '10.224.18.9'.

Related

Connecting to port 21 with Paramiko and got paramiko.ssh_exception.SSHException: Error reading SSH protocol banner

I'm trying to connect to am SFTP server through Paramiko. I don't have a host key. The following code is my attempt and it's giving me an error that says:
paramiko.ssh_exception.SSHException: Error reading SSH protocol banner
I notice that port is usually 22 in other given examples, but the SFTP port I was given is 21. And when I tried 22, it gave me another error saying
Unable to connect to port 22
Thank you in advance for your guidance and insight. Please let me know if I could provide more information.
from paramiko.client import SSHClient
from paramiko import AutoAddPolicy
client = SSHClient()
client.set_missing_host_key_policy(AutoAddPolicy())
client.connect(hostname="a_private_ip",
port=21,
username="user",
password="xxx")
sftp_handle = client.open_sftp()
Paramiko is an SFTP client. The SFTP uses port 22.
If you were given port 21, then it's most likely NOT SFTP. The port 21 is used by FTP. Encrypted variant of FTP, called also FTPS, uses 21 too. And people sometimes mistake it for SFTP.
For FTP use FTP class from ftplib. For FTPS use FTP_TLS class from ftplib.

paramiko.ssh_exception.NoValidConnectionsError: [Errno None] Unable to connect to port 22 using AWS Elastic Beanstalk

This is my first post so hopefully it is appropriate and not redundant.
I have an application I have deployed on AWS Elastic Beanstalk using a Flask Dash API. I have a snippet with the API that needs to connect to my Raspberry Pi remotely (SSH) and parse out some file.
This code snippet works flawlessly on my local machine
I can easily putty/ssh into my RPi on port 22
On my 1st router I have port 22 opened tcp/udp
On my 2nd router I have a NAT Forwarding Virtual Server rule for port 22 to direct to my RPI's static IP address
import paramiko
import json
client = paramiko.client.SSHClient()
hostname='example'
port=22
username='pi'
password='masked'
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.load_system_host_keys()
print('loaded client')
client.connect(hostname, port, username, password)
sftp_client = client.open_sftp()
localFilePath='./some_file.json'
sftp_client.get('/home/pi/some_file.json', localFilePath)
sftp_client.close()
I get error paramiko.ssh_exception.NoValidConnectionsError: [Errno None] Unable to connect to port 22 on
I am assuming this is some sort of networking access issue on the AWS side or possibly my router. I can easily connect to my RPi from outside of my own network also. I tried to add some inbound/outbound rules on my EC2 load balancer, but even opening it up completely did not resolve the issue. I have raked through the webs and cannot find many answers, so I am hoping someone has suggestions which can also be beneficial to others.
Thanks!
EC2 Instance SG Rules
Xfinity has a firewall enabled that is outside the router settings. Had to log into xFi mobile app, go to More, and My Services. Disable firewall. No whitelisting option which is terrible.

Connect to a host that doesn't answer to ping

I am trying to connect to a smtp port to automatically send emails through it. The problem is that when trying to connect to it with python smtplib it gives an error that it can't connect to the host. When trying to run nmap with the command
nmap -T4 -p 25,587,465
I get the following output:
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 2.12 seconds
When I add the -Pn option I get the following output:
Host is up.
PORT STATE SERVICE
25/tcp filtered smtp
465/tcp filtered smtps
587/tcp filtered submission
The python script that I have used is:
import smtplib, ssl
port = 465
password = "password"
email = "my#mail"
hostname = "hostname"
context = ssl.create_default_context()
with smtplib.SMTP_SSL(hostname, port, context=context) as server:
server.login(email, password)
And this is the error I get:
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
I am running the code on a Windows 10 machine and using Python 3.7.5.
Is there any way for me to connect to one of the email ports and send emails through it through python or c/c++?

Service and version displayed via nmap scan for simple python socket server

I've got a simple python socket server. Here's the code:
import socket
host = "0.0.0.0" # address to bind on.
port = 8081
def listen_serv():
try:
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((host,port))
s.listen(4)
...
messages back and forth between the server and client
...
if __name__ == "__main__":
while True:
listen_serv()
When I run the python server locally and then scan with nmap localhost i see the open port 8081 with the service blackice-icecap running on it. A quick google search revealed that this is a firewall service that uses the port 8081 for a service called ice-cap remote. If I change the port to 12000 for example, I get another service called cce4x.
A further scan with nmap localhost -sV returns the contents of the python script
1 service unrecognized despite returning data. If you know the service/version,
please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port8081-TCP:V=7.25BETA1%I=7%D=8/18%Time=57B58EE7%P=x86_64-pc-linux-gn
SF:u%r(NULL,1A4,"\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\
SF:*\*\*\*\*\*\*\*\*\*\*\*\*\n\*\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x
SF:20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\
SF:x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\*\n\*\x20\x20\x20\x20\x20\x
SF:20Welcome\x20to\x20ScapeX\x20Mail\x20Server\x20\x20\x20\x20\*\n\*\x20\x
SF:20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\
SF:x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
SF:\x20\x20\*\n\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\
SF:*\*\*\*\*\*\*\*\*\*\*\*\nHere\x20is\x20a\x20quiz\x20to\x20test\x20your\
SF:x20knowledge\x20of\x20hacking\.\.\.\n\n\nAnswer\x20correctly\x20and\x20
SF:we\x20will\x20reward\x20you\x20with\x20a\x20shell\x20:-\)\x20\nQuestion
etc...
etc...
Is there a way I can customize the service and version descriptions that are displayed by nmap for my simple python server?
Found a solution by sending the following line as the first message from the server
c.send("HTTP/1.1 200 OK\r\nServer: Netscape-Enterprise/6.1\r\nDate: Fri, 19 Aug 2016 10:28:43 GMT\r\nContent-Type: text/html; charset=UTF-8\r\nConnection: close\r\nVary: Accept-Encoding\n\nContent-Length: 32092\r\n\n\n""")

How to Transfer Files from Client to Server Computer by using python script?

I am writing a python script to copy python(say ABC.py) files from one directory to another
directory with the same folder name(say ABC) as script name excluding .py.
In the local system it works fine and copying the files from one directory to others by
creating the same name folder.
But actually I want copy these files from my local system (windows XP) to the remote
system(Linux) located in other country on which I execute my script. But I am getting
the error as "Destination Path not found" means I am not able to connect to remote
that's why.
I use SSH Secure client.
I use an IP Address and Port number to connect to the remote server.
Then it asks for user id and password.
But I am not able to connect to the remote server by my python script.
Can Any one help me out how can I do this??
paramiko provides a SFTPClient that can be used to do this.
import paramiko
source = r'C:\Somedir\somefile.txt'
dest = r'/home/user/file.txt'
hostname = 'linux.server.com'
port = 22 # default port for SSH
username = 'user'
password = 'secret'
try:
t = paramiko.Transport((hostname, port))
t.connect(username=username, password=password)
sftp = paramiko.SFTPClient.from_transport(t)
sftp.put(source, dest)
finally:
t.close()
I used the same script, but my host failed to respond. My host is in different network.
WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

Categories