Python FTP module Errors Clarification
I set up a scheduled 'bat' file that will run five python FTP push scripts to push files to an external FTP server from my local PC. Under most normal circumstances, this process works fine. However, sometime there will be error during the process to the FTP server as reported by the traceback debug.
Traceback (most recent call last): File "push2.py", lin 13, in (module) ftp.login('X', 'X') File "X\Python\Python35\lib\ftplib.py", line 419, in login resp = self.sendcmd('PASS' + passwd) File "X\Python\Python35\lib\ftplib.py", line 272, in sendcmd return self.getresp() File "X\Python\Python35\lib\ftplib.py",line 235, in getresp resp = self.getmultiline() File "X\Python\Python35\lib\ftplib.py", line 221, in getmultiline line = self.getline() File "X\Python\Python35\lib\ftplib.py",, line 209, in getline raise EOFError EOFError
Is these error caused by the scripts I am using or is it due to some settings in my Filezilla Server or it is completely out of my control which is at the external party FTP server? Is there a delicate way to workaround bypassing these errors especially for error 1 since it is happening the most often?
My 'bat' file is below:
cd X:\FTP_Push\Location\1 python push1.py TIMEOUT 5 cd X:\FTP_Push\Location\2 python push2.py TIMEOUT 5 cd X:\FTP_Push\Location\3 python push3.py TIMEOUT 5 cd X:\FTP_Push\Location\4 python push4.py TIMEOUT 5 cd X:\FTP_Push\Location\5 python push5.py if NOT ["%errorlevel%"]==["0"] pause timeout 60
I added timeout of 5s inbetween each script because I thought that I am connecting to the FTP server too fast. But it does not fix the issues.
See also questions close to this topic
Function to apply on csv file to remove White spaces
How can I remove the white spaces from the data? The data is in CSV format. What function should I apply.
cuisine_type ... rest_name 0 Finger Food, North Indian, Italian,... ... Whattay Kitchen and Brew 1 North Indian, Chinese ... Brilram's Balaji Bhavan 2 South Indian, North Indian, Chinese... ... Adiga's
in function return prime numbers = TypeError: unorderable types: str() < int()
TypeError: unorderable types: str() < int()when trying to run the following code. Can somebody help me locate the problem?
def prime_numbers(nb): if nb < 0: return None if nb == 0: return  primes = [2, 3] n = primes[-1] + 2 while len(primes) < nb: for p in primes: if n % p == 0: break else: primes.append(n) n += 2 return primes print(prime_numbers(10)) print(prime_numbers(0))
Problem when running my code with python3 tkinter
I'm new to Python 3 programming and are getting errors that I can't seem to fix. I'm trying to make a text editor. This is the code:
import tkinter as tk class PyText: def __init__(self, master): master.title("Untitled - PyText") master.geometry("1200x700") if __name__ == "__main__": master = tk.TK() pt = PyText(master) master.mainloop()
Running it I get: Traceback (most recent call last): File "textEdit.py", line 12, in master = tk.TK() AttributeError: module 'tkinter' has no attribute 'TK'
How can I fix this??? Thank you for the help!
Find a keyword occurred today using Batch
I need to find All the ORA Errors in my log.txt file that has occurred today using batch program. I am not good with Batch so not able to add date time filter with my code below.
@echo off findstr /m "ORA-" Alert.txt if %errorlevel%==0 ( echo There is an ORA Error in Alert File! )
Errors in file:
2019-10-14T00:43:40.497493+01:00 Errors in file C:\R2DATABASE\PRODUCT\12.2.0\diag\rdbms\r2\r2\trace\r2_j000_11628.trc: ORA-12012: error on auto execute of job "R2"."R3NOTIFICATION_160328336632" ORA-06550: line 1, column 763: PLS-00201: identifier 'R3NOTIFICATION_PKG.GENERATENOTIFICATIONFORR3' must be declared ORA-06550: line 1, column 763: PL/SQL: Statement ignored 2019-10-14T00:43:42.029005+01:00 Errors in file C:\R2DATABASE\PRODUCT\12.2.0\diag\rdbms\r2\r2\trace\r2_j001_2524.trc: ORA-12012: error on auto execute of job "R2"."R3NOTIFICATION_160328336632" ORA-06550: line 1, column 763: PLS-00201: identifier 'R3NOTIFICATION_PKG.GENERATENOTIFICATIONFORR3' must be declared ORA-06550: line 1, column 763: PL/SQL: Statement ignored
Date time format -
.bat file execution PreBuild Event in Visual Studio - set /a
I have a batch file executing in the prebuild event of Visual Studio 2019.
for /f "tokens=2" %%i in ('svn info -rHEAD https://repositoryURL^|find "Revision"') do ( echo %%i set /a "b=%%i+1" echo %a% powershell -Command "(gc c:\PathToFile\MainWindow.xaml) -replace 'x:Name=\"Lbl_Version\" Content=\"Revision: %%i\"', 'x:Name=\"Lbl_Version\" Content=\"Revision: %b%\"' | Out-File -encoding UTF8 c:\PathToFile\MainWindow.xaml" )
&&i = 17 at the moment.
This works beautifully if I execute the batch file from cmd. However when executed via Visual Studio, the set /a command seems to return empty. (The String gets replaced with an empty "Revision: " instead of "Revision: 18")
How can I get arround that issue? I don't understand the problem since it works when executed via cmd.
Batch File: "Environment Variable Not Defined" on a path
I have the following in a batch file
for /f "delims=" %%a in ("C:\Program Files (x86)\Wowza\creds.txt") do set %%a net use J: https://csv/dav %p% /user:%u% /persistent:yes
I get an error:
Environment variable C:\Program Files (x86)\Wowza\creds.txt not defined
What do I need to resolve this?
Secondly, it works for all colleagues apart from one. Same laptop make, model and build. I used my details and it failed on his but worked on mine.
What fails is that it asks for the credentials to map the drive instead of taking them from the file
Kubernetes ftp deploy simple example
Last week I was trying to deploy ftp in K8s but I cound not deploy it. I tried to find some simple example but I only found very hard examples.
Can you give me some simple examples?
Apache Commons : Connection closed without indication
I have software using FTP to deposit files, the software runs on several machines. Windows 10 machines seem to be the most affected. The software works correctly for several days/weeks and then stops and does not work again until restart. When again it works correctly until it stops again.
I have disabled StatefulFTP, this solution seems to resolve issues on Windows 7 but does not work on Windows 10. The command is :
netsh advfirewall StatefulFTP disable
I am using Apache Commons Net v3.6
<dependency> <groupId>commons-net</groupId> <artifactId>commons-net</artifactId> <version>3.6</version> </dependency>
I am receiving the following error
Caused by: org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication. at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:324) at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:300) at org.apache.commons.net.ftp.FTP.getReply(FTP.java:732) at org.apache.commons.net.ftp.FTPClient.completePendingCommand(FTPClient.java:1853)
FTP Support to be Withdrawn
I'm developing a Photography website that functionally depends on the FTP facility built-in to Chrome. Chrome and Firefox are the only browswers that have properly implemented FTP. Users of the website can, with a single click of a button, download all their photos and videos directly from an FTP Server. This is currently working in development, and I'll be releasing this to production shortly.
I understand now that Google is going to withdraw FTP functionality from Chrome from version 82. This will kill my business. What can I do about this?
How to properly close the file opened by the class?
I have a class I use to track the progress of an ftp download (using
multiprocessingto download several files at once.
This is my first attempt at using a class in Python and I am doubtful whether I am closing a file I opened inside the class. The code snippets I think relevent are given below:
class track_transfer: def __init__(self, size, fname): self.file_name=fname self.size_in_bytes=size self.downloaded=0 self.file=open(fname, 'wb') def __del__(self): try: self.file.close() self.file=None except: pass def update(self): self.downloaded=self.file.tell() if self.downloaded==self.size_in_bytes: self.file.close()
As you can see, I try to close the files at two places: one inside the finalizer another in a class method
What I wanted to know is will my file be closed correctly when I use this class?
Or is there a better method to follow?
I think I may need to provide more information here.
The class track_transfer has another method named progress(self, data) defined as follows:
def progress(self, data): self.file.write(data) self.update()
Instantiating the classAdded more information,
and downloading the file,
ftp.retrbinary("RETR %s" %(fname), callback=tracker.progress)
where ftp.retrbinary() is a method defined in the ftplib library to retrieve a file as binary from an ftp server. This will call the tracker objetc's progress method whenever a block of data is received. This means that the method progress() will be called several times when downloading a file.
Read FTP file contents in Python and use it at the same time for Pandas and directly
I am trying to download a file from an FTP server in memory, transform it to a dataframe but also return it as bytes. Code as follows:
import io import pandas as pd from ftplib import FTP ftp_connection.cwd(ftp_folder) download_file = io.BytesIO() ftp_connection.retrbinary('RETR ' + str(file_name), download_file.write) download_file.seek(0) file_to_process = pd.read_csv(download_file, engine='python')
After searching on Stack Overflow, the suggestion was to just read the io stream:
download_file.read() ValueError: I/O operation on closed file.
Not sure what to try next, without writing the file somewhere and reading it again as bytes.
Trying to store a png image using ftplib and storbinary ==> UnicodeEncodeError
I'm new to StackOverflow so I'm really excited! 😊
I'm having the following issue with my code: I am trying to store a 'png' image into an FTP server (a screenshot of a website).
I'm using ftplib and selenium (with webdriver):
driver.get(<someURL>) screenshot = driver.save_screenshot(driver.title + '.png') ftp.storbinary("STOR <PathToServer>" + driver.title + '.png', open(driver.title + '.png', 'rb'))
This method works when the website is written with Latin characters, the problem is that the image can be the screenshot of a website located in Thailand, China, or Egypt, for instance. In that case, the line with:
open(driver.title + '.png', 'rb')
returns the infamous error:
UnicodeEncodeError: 'latin-1' codec can't encode character '\u1ec7' in position 60: ordinal not in range(256)
I understand that storbinary is accepting only binary numbers (as the name of that method implies). However, what I don't understand is how I can "encode" the png so that it will not lead to that error, and so that it can be stored successfully into the FTP server.
Thank you so very much! Any help, or comment, or insight, would be deeply appreciated. Best!